Hello: I have an application in which it would be ideal to run two background HTTP requests in serial. This page on StackExchange suggests to use Background Batch. I feel like that might be a bit heavy, and the other approach that comes to mind is to run the second request within the first request's designated callback:
Idea
background_process_http_request('http://www.example.com/stuff/', array('callback' => 'mycallback'));
function mycallback($result) {
// Actually, ignore $result and just run the second request
background_process_http_request('http://www.example.com/things/');
}
This would work well, except I'd really like to be able to pass in some additional arguments for the callback function, something more like this:
Better idea...?
background_process_http_request('http://www.example.com/stuff/', array('callback' => 'mycallback', 'callback_args' => array(1,2,3)));
function mycallback($result,$args) {
// Actually, ignore $result and just run some other requests (using $args)
foreach ($args as $arg) {
background_process_http_request('http://www.example.com/things/'.$arg);
}
}
Is this a worthwhile feature request? ... or would it be simpler/better to implement the "argument passing" using objects?
Comments
Comment #0.0
holtzermann17 CreditAttribution: holtzermann17 commentedfix formatting
Comment #1
gielfeldt CreditAttribution: gielfeldt commentedHi
For regular http requests (not starting background processes as such), it's possible to issue them in a "sliding window" fashion using the "postpone" option.
The above will run launch all 10 ten requests, but only 5 at time. For serial execution, you could just set the "limit" to 1.
In this case (and the one you wrote), the 'callback' option is not used as part of the URL, but will be called when the request is finished and have the request object passed as an argument.
Comment #2
holtzermann17 CreditAttribution: holtzermann17 commentedHi Gielfeldt - thanks very much for the tip! That works well for me in combination with
background_process_start
. Cheers!Comment #3.0
(not verified) CreditAttribution: commentedmake idea 2 more clear