note 95088 added to function.curl-multi-exec

From: Date: Sat, 12 Dec 2009 21:50:50 +0000
Subject: note 95088 added to function.curl-multi-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-163895@lists.php.net to get a copy of this message
If you have problems with client timeouts (browser, wget) - like I did - add some keep alive code. <?php $locations = array( "file1" => "[url here]", "file2" => "[url here]", "file3" => "[url here]", "file4" => "[url here]" ); $mh = curl_multi_init(); $threads = null; foreach ($locations as $name => $url) { $c[$name]=curl_init($url); $f[$name]=fopen ($name.".xml", "w"); curl_setopt ($c[$name], CURLOPT_FILE, $f[$name]); curl_setopt ($c[$name], CURLOPT_TIMEOUT,600); curl_multi_add_handle ($mh,$c[$name]); } $t1 = time(); do { $n=curl_multi_exec($mh,$threads); if (time() > $t1 + 2) { echo "keep-alive" ."<br/>"; $t1 = time(); } } while ($threads > 0); foreach ($locations as $name => $url) { curl_multi_remove_handle($mh,$c[$name]); curl_close($c[$name]); fclose ($f[$name]); } curl_multi_close($mh); ?> ---- Server IP: 87.124.86.47 Probable Submitter: 86.172.49.100 (proxied: 86.172.49.100) ---- Manual Page -- http://www.php.net/manual/en/function.curl-multi-exec.php Edit -- https://master.php.net/note/edit/95088 Del: integrated -- https://master.php.net/note/delete/95088/integrated Del: useless -- https://master.php.net/note/delete/95088/useless Del: bad code -- https://master.php.net/note/delete/95088/bad+code Del: spam -- https://master.php.net/note/delete/95088/spam Del: non-english -- https://master.php.net/note/delete/95088/non-english Del: in docs -- https://master.php.net/note/delete/95088/in+docs Del: other reasons-- https://master.php.net/note/delete/95088 Reject -- https://master.php.net/note/reject/95088 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163895) next »