php - ParallelCurl with CURLOPT_WRITEFUNCTION -


I'm trying to use it, with which it has been connected. Currently I have the code present:

  function requested ($ content, $ url, $ ch, $ user_data) {echo "request complete:", $ content, "\ n "; } $ PC = new parallel crawl (); $ Server = server :: loadNewAllFromDB (); // Server provides an array of objects that store the connection information foreign currency ($ server server $ server) {$ PC- & gt; Set Option (Array (CURLOPT_USERAGENT = & gt; 'My Userager String', Quropy_WRITEFUNCTION = & gt; Function ($ CH, $ string) {echo "Calling! |", $ String; Return Stellon ($ string);} )); // print_r ($ PC-> Option); $ PC- & gt; StartRoot ('http: //'. $ Server- & gt; Address. ':'. $ Server- & gt; Portbase. '/ Someurl'), 'Requested' ';); } $ Pc- & gt; Finihill all requests ();   

Now, what I hope to be, is to tell my anonymous function, when the data in the CRL is output, rather than just ignoring this fact That CURLOPT_WRITEFUNCTION is set exactly

Note that if I am not using ParallelCurl, then I can set the very anonymous function as CURLOPT_WRITEFUNCTION exactly. It seems that my work is being overridden somewhere later. I have also verified that it is actually being established. You can see the line I commented on, // print_r ($ pc-> option) . It produces my finished object.

Any thoughts on this will be most appreciated. Thank you.

It became a bug with either parallel curls, or curl_set_opt_array (). Here is the function in the parallel kernel: Start a fetch from the

  // $ url address, call the $ callback function by passing the optional $ // user_data value. Callback should accept 3 logic, url, curl handle and user / data, such as on_request_done ($ url, $ ch, $ user_data); Public function startRequest ($ url, $ callback, $ user_data = array (), $ post_fields = null) {if ($ this-> max_request & gt; 0) $ this- & gt; Waiting Output UsageDropperBello ($ this-> Max_requests); $ Ch = curl_init (); Curl_setopt_array ($ ch, $ this-> option); Curl_setopt ($ ch, CURLOPT_URL, $ url); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, TRUE); If (isset ($ post_fields)) {curl_setopt ($ ch, CURLOPT_POST, TRUE); Curl_setopt ($ CH, CURLOPT_POSTFIELDS, $ post_fields); } Curl_multi_add_handle ($-> multi-generating, $ ch); $ This- & gt; Outstanding_request [$ ch] = array ('url' = & gt; $ url, 'callback' = & gt; $ callback, 'user_data' => $ user_data,); $ This- & gt; CheckForCompletedRequests (); }   

The problem is now where sits curl_setopt_array ($ ch, $ this-> option) If I take it down from all the other curl_setopt () , then it works fine. Strange thing is that my user-agent parameter I the same array Passed as CURLPOT_WRITEFUNCTION was working fine. Therefore, it seems that curl_setpot_array () behaves differently when objects are given values ​​in the array. Anyway, just walk the call worked fine. My revised function: Start a fetch from

  // $ url address, calling call $ is $ $ $ the user_data value. Callback should accept 3 logic, url, curl handle and user / data, such as on_request_done ($ url, $ ch, $ user_data); Public function startRequest ($ url, $ callback, $ user_data = array (), $ post_fields = null) {if ($ this-> max_request & gt; 0) $ this- & gt; Waiting Output UsageDropperBello ($ this-> Max_requests); $ Ch = curl_init (); Curl_setopt ($ ch, CURLOPT_URL, $ url); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, TRUE); If (isset ($ post_fields)) {curl_setopt ($ ch, CURLOPT_POST, TRUE); Curl_setopt ($ CH, CURLOPT_POSTFIELDS, $ post_fields); } Curl_setopt_array ($ ch, $ this-> option); Curl_multi_add_handle ($ this-> Multi-Headl, $ ch); $ This- & gt; Outstanding_request [$ ch] = array ('url' = & gt; $ url, 'callback' = & gt; $ callback, 'user_data' => $ user_data,); $ This- & gt; CheckForCompletedRequests (); }    

Comments