Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need example of "async_request" #6

Open
phpconnect opened this issue Jun 12, 2014 · 1 comment
Open

need example of "async_request" #6

phpconnect opened this issue Jun 12, 2014 · 1 comment

Comments

@phpconnect
Copy link

Can you let us know the example of "async_request" model?

@langemeijer
Copy link

There is one in the code already. Because all requests are performed asynchronously in the fastcgi protocol. Look at the code below:

public function request(array $params, $stdin)
{
    $id = $this->async_request($params, $stdin);
    return $this->wait_for_response($id);
}

With the current state of this project you could start multiple requests

    $id1 = $this->async_request($params1, $stdin1);
    $id2 = $this->async_request($params2, $stdin2);

And ready the results later:

$result1 = $this->wait_for_response($id1);
$result2 = $this->wait_for_response($id2);

If the $id2 request finishes before the $id1 request, the results are retrieved and returned on the wait_for_response($id2) call.

Sadly there currently is no way to execute code (like a callback or something) as soon a request is ready. Nothing is stopping you to fork, implement and contribute of course.

If you are looking for a non-blocking implementation, follow issue #12 to see if that is going to happen. The non-blocking socket model requires a very different type of code and as a result will always support in a callback-like model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@langemeijer @phpconnect and others