The website root directory contains a test.html file with only a text demo. {Code ...} this is curl. php {code ...} 500 concurrent threads are set, so the result is output after about 10 seconds. The program does not respond during the waiting period. The result I want to achieve is that every time a curl thread completes the request...
The website root directory contains a test.html file with only a text demo.
demo
This is curl. php
$ Ch) {curl_multi_add_handle ($ mh, $ ch) ;}$ running = null; do {curl_multi_exec ($ mh, $ running);} while ($ running> 0 ); // start multi-threaded foreach ($ chArr as $ k => $ ch) {$ result [$ k] = curl_multi_getcontent ($ ch ); // here the output content echo "$ result [$ k] \ n" curl_multi_remove_handle ($ mh, $ ch);} curl_multi_close ($ mh );
500 concurrent threads are set, so the result is output after about 10 seconds. The program does not respond during the waiting period.
The result I want to achieve is that every time a curl thread request is completed, a result is immediately output on the terminal: demon.
How can we implement it? If Php cannot be implemented, NodeJs and Python solutions are acceptable. thank you.
Reply content:
The website root directory contains a test.html file with only a text demo.
demo
This is curl. php
$ Ch) {curl_multi_add_handle ($ mh, $ ch) ;}$ running = null; do {curl_multi_exec ($ mh, $ running);} while ($ running> 0 ); // start multi-threaded foreach ($ chArr as $ k => $ ch) {$ result [$ k] = curl_multi_getcontent ($ ch ); // here the output content echo "$ result [$ k] \ n" curl_multi_remove_handle ($ mh, $ ch);} curl_multi_close ($ mh );
500 concurrent threads are set, so the result is output after about 10 seconds. The program does not respond during the waiting period.
The result I want to achieve is that every time a curl thread request is completed, a result is immediately output on the terminal: demon.
How can we implement it? If Php cannot be implemented, NodeJs and Python solutions are acceptable. thank you.
Nodejs is asynchronous.
You can use ob_start () and ob_flush () to disable output_buffering. the default value is 4 K. If this parameter is not set, it will be invalid because you have too little content. If it is accessed by the browser, there will be no solution, because the browser has a buffer, too little will not be able to see the effect. Run the following command to test OK. if the page does not have the ini_set permission, go to php. ini and set output_buffering = 0.
By the way, the number of cycles is 500. The local php7 test is executed for 1 to 2 seconds, and php5.4 takes 28 seconds.
$ch){ curl_multi_add_handle($mh,$ch);}$running = null;do{ curl_multi_exec($mh,$running);}while($running > 0);foreach($chArr as $k => $ch){ $result[$k]= curl_multi_getcontent($ch); echo "$result[$k]\n"; ob_flush(); flush(); sleep(1); curl_multi_remove_handle($mh,$ch);}ob_end_flush();curl_multi_close($mh);
Although it is multi-threaded, it is synchronous, not asynchronous. php does not seem to have the asynchronous capability.