PHP use curl_multi_exec(), print HTTP Status -
I do not know how to print curl_multi_exec (), HTTP status.
First I use this:
function testurl ($ url) {$ ch = curl_init ($ url); // curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla / 5.0 (Windows NT 6.1; WOW64; rv: 25.0) Gecko / 20100101 Firefox / 25.0"); Curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, TRUE); Curl_setopt ($ CH, CURLOPT_FOLLOWLOCATION, TRUE); Curl_exec ($ ch); $ Info = curl_getinfo ($ ch); Curl_close ($ ch); Return $ info [http_code]; }
This will print 302, 200 ... but if I use this function for 10-15 URLS, the script will work for about 15 seconds. It's really too long.
Then I try to use it:
$ nodes = array ('http://www.google.com', 'http: // www. .microsoft.com ',' http://www.rustyrazorblade.com '); $ Node_count = Count ($ node); $ Curl_arr = array (); $ Master = curl_multi_init (); ($ I = 0; $ i & lt; $ node_count; $ i ++) for $ {$ url = $ nodes [$ i]; $ Curl_arr [$ i] = curl_init ($ url); Curl_setopt ($ curl_arr [$ i], CURLOPT_RETURNTRANSFER, true); Curl_multi_add_handle ($ master, $ curl_arr [$ i]); } Tax {curl_multi_exec ($ master, $ running); } While ($ running> gt; 0); Echo "Result:"; {$ Results = curl_multi_getcontent ($ curl_arr [$ i]) for $ ($ I = 0; $ i & lt; $ node_count; $ i ++); Echo ($ i. "\ N". $ Result. "\ N"); } Dumb 'done';
But I do not know why it does not print anything if the link is good or does not work.
How to use curl_multi_exec () to print, if the link is HTTP status 200?
This will print the URL response code.
$ node = array ('http://www.google.com', 'http://www.microsoft.com', 'http://www.rustyrazorblade.com' ); $ Node_count = Count ($ node); $ Curl_arr = array (); $ Master = curl_multi_init (); ($ I = 0; $ i & lt; $ node_count; $ i ++) for $ {$ url = $ nodes [$ i]; $ Curl_arr [$ i] = curl_init ($ url); Curl_setopt ($ curl_arr [$ i], CURLOPT_RETURNTRANSFER, true); Curl_multi_add_handle ($ master, $ curl_arr [$ i]); } Tax {curl_multi_exec ($ master, $ running); } While ($ running> gt; 0); Echo "Result:"; ($ Info = $ i] = curl_getinfo ($ curl_arr [$ i], CURLINFO_HTTP_CODE);} Print_r ($ info)
Comments
Post a Comment