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

Make it easy to find out "which response is which" #14

Open
stil opened this issue Feb 12, 2015 · 5 comments
Open

Make it easy to find out "which response is which" #14

stil opened this issue Feb 12, 2015 · 5 comments
Assignees
Milestone

Comments

@stil
Copy link
Owner

stil commented Feb 12, 2015

It's a very popular problem - how to know which response is which. They may appear in random order, so we need to add a feature allowing to associate responses with their starting parameters.

@stil stil self-assigned this Feb 12, 2015
@tonivdv
Copy link

tonivdv commented Feb 12, 2015

Hey @stil ,

Can you share a specific use case? I guess today you could simple build this in your application logic?!

@stil
Copy link
Owner Author

stil commented Feb 12, 2015

An use case could be for example fetching list of paginated offers from online shopping website. You would make 10 requests to download first 10 pages of offers.

http://www.morele.net/komputery/sieci/routery-48/0,0,,,,,,,,,/1/
http://www.morele.net/komputery/sieci/routery-48/0,0,,,,,,,,,/2/
http://www.morele.net/komputery/sieci/routery-48/0,0,,,,,,,,,/3/
...

Then you send requests in parallel. Responses may appear in different order, and you wouldn't know which page you have just fetched.

Currently there are two ways to associate responses:

  • Set dynamic attribute to Request object, for example:
$i = 1;
$request = new \cURL\Request("http://www.morele.net/komputery/sieci/routery-48/0,0,,,,,,,,,/$i/");
$request->_page = $i;
  • Create a requests map with request object hash as keys and request context (ie. page number) as value.

First approach is unelegant and some IDEs will complain about setting dynamic attributes. And second requires a few additional lines of code.
I think I'm going just add setContext() method to Request class which would accept mixed values, so you can store custom information about this request.

Or, in more object oriented way: setContext() would accept RequestContextInterface. Then you would need to derive your class from this interface.

@tonivdv
Copy link

tonivdv commented Feb 12, 2015

Ok I see. Thanks for the detailed response.

Your third solution seems most appropriate. Especially with interface implementation, because it allows freedom to the user to implement whatever he wants it for.

Not sure about the setContext naming though. That being said I don't have any alternatives to share.

@wozzup
Copy link

wozzup commented Feb 14, 2015

stil commented 2 days ago
I think I'm going just add setContext() method to Request class which would accept mixed values, so you can store custom information about this request.
Or, in more object oriented way: setContext() would accept RequestContextInterface. Then you would need to derive your class from this interface.

awesome! can't wait

@wozzup
Copy link

wozzup commented Feb 14, 2015

$request->_page = $i;

worked for me, in the

$queue->addListener('complete', function (\cURL\Event $event)
{
    var_dump($event->request->_page);
}

thanks stil

@stil stil added this to the v1.2 milestone Feb 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants