I'm trying to use httprl to submit a number of different POSTS to the same url (all with different data) in parallel. However, getting the response to each of these requests is very important, and when I run httprl_send_request, the resulting array only has one item, for the last request that completed I think.

Is this expected behaviour?

Comments

mikeytown2’s picture

Sadly this is expected for the 1.x branch. You can add an anchor (#) to the URL to separate them out though, so not all is lost. Things could change in the 2.x branch. Open to ideas on how you would like it to work.

Example below. The $data array will contain 4 different URLs.

$urls = array();
$urls[] = 'http://example.com/#1';
$urls[] = 'http://example.com/#2';
$urls[] = 'http://example.com/#3';
$urls[] = 'http://example.com/#4';
httprl_request($urls);
$data = httprl_send_request();
echo httprl_pr($data);

// You can access #2 directly as well.
echo httprl_pr($data['http://example.com/#2']);
obrienmd’s picture

Right - I used a random query parameter for now to work around it. Honestly, in 2.x, I think it makes sense to just have a numerically-keyed array of responses with the url being included in each one somewhere?

mikeytown2’s picture

Issue is I like the ability to access the URLs info via key; the key being the URL.

obrienmd’s picture

Yeah, I can see why you would in many use cases. Hrm... I suppose I don't really have an issue with mocking up a query param or anchor :) I'll ruminate a bit more...

obrienmd’s picture

Thought about it a bit more... I suppose you could return an array that looked like this (example is 2 requests to Google and 1 to Yahoo):

array(
  'http://www.google.com' => array(
    0 => $FIRST_RESPONSE_FROM_THIS_URL,
    1 => $SECOND_RESPONSE_FROM_THIS_URL,
  ),
  'http://www.yahoo.com' => array(
    0 => $ONLY_RESPONSE_FROM_THIS_URL,
  ),
)
mikeytown2’s picture

Status: Active » Postponed
Issue tags: +2.x Roadmap

Going to postpone this issue. In the future we can do an array of arrays but this would be an API breaking change thus it would have to go in a new version.

obrienmd’s picture

Cool, thanks!

mikeytown2’s picture

Version: 7.x-1.7 » 7.x-1.x-dev