I am trying to enter a site and then call many URLs to get source and scrape of images I do It works fine using regular curls, but when I try to use multi_curl, I get an accurate response. That is because I will only have to enter once the curl resource is restored (it works fine with regular curls) and I think this is the reason that it is returning the same reaction.
Does anyone know how to use Multi_curl but first authenticate?
Here's the code I'm using:
& lt; Php // License: Public Domain // Author reject the copyright of this source code. // Author: Shailesh N. Humbad // Source: http://www.somacon.com/p539.php/ Date: 6/4/2008 // index.php // Get parallel and print the total time $ S = microgram (true); // URL $ urls = define array ("http: //localhost/r.php?echo = request1", "http: //localhost/r.php?echo = request2", "http: // localhost / r .php? Echo = request 3 "); $ Pg = new parallelgate ($ urls); Print "
Total Time:" .Round (Microtim (True) - $ s, 4). "Seconds"; // Class and transfer class to run parallel received requests ParallelGet {function __construct ($ urls) {// Request a request for each URL $ mh = curl_multi_init (); $ Count = 0; $ Ch = curl_init (); Forex Currency ($ url = $ url = $ url) {$ count ++; If ($ count == 1) {// enter url for post form curl_setopt ($ ch, CURLOPT_URL, 'https://www.example.com/login.php'); // Enable HTTP post curl_setopt ($ ch, CURLOPT_POST, 1); // Set Post Parameters: Form values for each field curl_setopt ($ ch, CURLOPT_POSTFIELDS, 'user = myuser & password = mypassword');); // Copy the classic browser's behavior: handle cookies curl_setopt ($ CH, CURLOPT_COOKIEJAR, actual path ($ _ server ['DOCUMENT_ROOT']). '/cookie.txt'); Setting the #CURLOPT_RETURNTRANSFER variable to 1 will not force the cross # to print the results of its query. # Instead, this will return the results as a string return value # Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1) from curl_exec () instead of true true / falls; // Get the first request (form login) curl_exec ($ ch); } $ Ch = curl_init ($ url); Curl_setopt ($ CH, CURLOPT_COOKIEFILE, actual path ($ _ server ['DOCUMENT_ROOT']). '/cookie.txt'); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, 1); $ Ch_array [$ i] = $ ch; Curl_multi_add_handle ($ mh, $ ch_array [$ i]); } // Start requesting {$ execReturnValue = curl_multi_exec ($ mh, $ runningHandles); } While ($ execReturnValue == CURLM_CALL_MULTI_PERFORM); // Loop and continue processing while requesting ($ Running Handle & amp; $ execReturnValue == CURLM_OK) {// Always wait for the network $ numberReady = curl_multi_select ($ mh); If ($ numberReady! = -1) {// Drag into any new data, or at least control timeout {$ execReturnValue = curl_multi_exec ($ mh, $ runningHandles); } While ($ execReturnValue == CURLM_CALL_MULTI_PERFORM); }} // Check any errors ($ execReturnValue! = CURLM_OK) {trigger_error ("curl multi mercury error $ execReturnValue \ n", E_USER_WARNING); } // extract content forash ($ url as $ url = $ url) {// check errors $ curlError = curl_error ($ ch_array [$ i]); If ($ curlError == "") {$ res [$ i] = curl_multi_getcontent ($ ch_array [$ i]); } And {print "curl error $ i: $ curlError handle \ n"; } // Close the handle and close curl_multi_remove_handle ($ mh, $ ch_array [$ i]); Curl_close ($ ch_array [$ i]); } // curl_multi clean the handle curl_multi_close ($ mh); // Print print data print_r ($ res); }}? & Gt;
You also need to enable / enable the Couragees. For this, see the documentation, do not forget to make cookies (blank files) with curl permission to read and write.
$ cookie = tempnam ("/ tmp", "cURLCOOKIE"); $ Ch = curl_init (); Curl_setopt ($ ch, CURLOPT_URL, $ url); Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie);
Comments
Post a Comment