PHP: http GET/POST in a truly async fashion -


basically, i'm looking way following in php:

http_get_or_post('an.url', 'or.two');  // work here, not worrying http going on in background.  $r = wait_for_and_get_the_results_of_the_http_requests() 

and maybe more curl experience can confirm curl_multi i'm looking for.

from gather http://php.net/manual/en/function.curl-multi-init.php, sample there might give me need:

$ch1 = curl_init(); curl_setopt($ch1, curlopt_url, "http://www.php.net/"); curl_setopt($ch1, curlopt_header, 0); $mh = curl_multi_init(); curl_multi_add_handle($mh,$ch1);  $active = null; {     $mrc = curl_multi_exec($mh, $active); } while ($mrc == curlm_call_multi_perform);  // now, free time consuming work here , not worry // calling curl_multi_exec every , facilitate background // http / socket processes?  while ($active && $mrc == curlm_ok) {     if (curl_multi_select($mh) != -1) {         {             $mrc = curl_multi_exec($mh, $active);         } while ($mrc == curlm_call_multi_perform);     } }  curl_multi_remove_handle($mh, $ch1); curl_multi_close($mh); 

now, main question is, understanding of correct?

1) first loop take care of sending out / writing requests sockets.

2) of http / socket stuff happen in background after requests have been sent, leaving me free other stuff without having periodically call curl_multi_exec make sure buffer not full somewhere , needs kick keep going.

3) second loop wait outstanding response data arrive , finish reading , processing responses.

now, still not async - might become blocked on writing requests should socket write buffers fill up, in scenario that's not problem, i'm worried having call curl_multi_exec while i'm doing other stuff in middle, whole thing not freeze until next chance call curl_multi_exec.

i'm fine being case general scenario of 2k-4k responses, bigger responses getting stuck doing nothing in background until second loop.

is how curl_multi works? if not, can suggest done in php?

curl_multi work small piece @ time. every call curl_multi_exec little fragment of transfer operation , once you've called enough number of times , data has been sent , received, done.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -