php-doc-en/reference/yar/yar_concurrent_client/loop.xml
Xinchen Hui 018f2740b7 Add reset
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@338103 c90b9560-bf6c-de11-be94-00142212c4b1
2015-11-10 10:05:47 +00:00

141 lines
4.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="yar-concurrent-client.loop" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Yar_Concurrent_Client::loop</refname>
<refpurpose>Send all calls</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <modifier>static</modifier> <type>boolean</type><methodname>Yar_Concurrent_Client::loop</methodname>
<methodparam choice="opt"><type>callable</type><parameter>callback</parameter></methodparam>
<methodparam choice="opt"><type>callable</type><parameter>error_callback</parameter></methodparam>
</methodsynopsis>
<para>
Send all registed remote RPC calls.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>callback</parameter></term>
<listitem>
<para>
If this callback is set, then Yar will call this callback after all
calls are sent and before any response return, with a $callinfo NULL.
</para>
<para>
Then, if user didn't specify callback when registering concurrent call,
this callback will be used to handle response, otherwise, the callback
specified while registering will be used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>error_callback</parameter></term>
<listitem>
<para>
If this callback is set, then Yar will call this callback while error
occurred.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>Yar_Concurrent_Client::loop</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
function callback($retval, $callinfo) {
if ($callinfo == NULL) {
echo "Now, all requests are sent, and no any response available\n";
} else {
echo "This is a remote call response, the method name is", $callinfo["method"],
". calling sequence is " , $callinfo["sequence"] , "\n";
var_dump($retval);
}
}
function error_callback($type, $error, $callinfo) {
error_log($error);
}
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback");
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters")); // if the callback is not specificed,
// callback in loop will be used
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_PACKAGER => "json"));
//this server accept json packager
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_TIMEOUT=>1));
//custom timeout
Yar_Concurrent_Client::loop("callback", "error_callback"); //send the requests,
//the error_callback is optional
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Now, all requests are sent, and no any response available
This is a remote call response, the method name issome_method. calling sequence is 4
string(11) "some_method"
This is a remote call response, the method name issome_method. calling sequence is 1
string(11) "some_method"
This is a remote call response, the method name issome_method. calling sequence is 2
string(11) "some_method"
This is a remote call response, the method name issome_method. calling sequence is 3
string(11) "some_method"
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>Yar_Concurrent_Client::call</methodname></member>
<member><methodname>Yar_Concurrent_Client::reset</methodname></member>
<member><methodname>Yar_Server::__construct</methodname></member>
<member><methodname>Yar_Server::handle</methodname></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->