Using the AlphaRPC client is quite simple. It consists of three steps:
Also see check the example client.
You start with configuring the Client:
use AlphaRPC\Client\Client; $client = new Client(); // Tell it where to find the Client Handler $client->addManager('tcp://127.0.0.1:61002');
Then, you have to perform a request. You have two choices here:
In case of a synchronous request, you do:
$params = array('Hello World!'); $response = $client->request('reverse', $params);
Now, you will have the response in the
In case of an asynchronous request, you need two steps:
$params = array('Hello World!'); // Start the request. $request = $client->startRequest('reverse', $params); // Do something else. sleep(1); // Fetch the response (and wait for it if it is not yet available). $waitForIt = true; $response = $client->fetchResponse($request, $waitForIt);
Now, again you will have the response in the
$response variable again.
Now, you may have noticed that we included a
$waitForIt parameter when fetching the response. With this flag, you can indicate whether you want to wait until the response is available.
If you set this parameters to
false and the response is not yet available, you will receive a
You can safely try to fetch the response again.
NOTE: fetching a response is not necessary! If you just want to send a request to a Worker, without caring about the result (in the client), you may choose not to fetch the response. That effectively makes your request a background taks.
If you want to run your own actions, see Creating a Worker.