Req #64191 [NEW]: "curl_multi_close" example code needlessly use 100% cpu..

From: Date: Mon, 11 Feb 2013 19:48:59 +0000
Subject: Req #64191 [NEW]: "curl_multi_close" example code needlessly use 100% cpu..
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9514@lists.php.net to get a copy of this message
From: divinity76 at gmail dot com Operating system: Irrelevant PHP version: Irrelevant Package: Documentation problem Bug Type: Feature/Change Request Bug description:"curl_multi_close" example code needlessly use 100% cpu.. Description: ------------ as of writing, the example code for curl_multi_close is <?php // create both cURL resources $ch1 = curl_init(); $ch2 = curl_init(); // set URL and other appropriate options curl_setopt($ch1, CURLOPT_URL, "http://www.example.com/"); curl_setopt($ch1, CURLOPT_HEADER, 0); curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/"); curl_setopt($ch2, CURLOPT_HEADER, 0); //create the multiple cURL handle $mh = curl_multi_init(); //add the two handles curl_multi_add_handle($mh,$ch1); curl_multi_add_handle($mh,$ch2); $running=null; //execute the handles do { curl_multi_exec($mh,$running); } while ($running > 0); //close the handles curl_multi_remove_handle($mh, $ch1); curl_multi_remove_handle($mh, $ch2); curl_multi_close($mh); ?> i believe this code will be stuck using all cpu it can on do{curl_multi_exec($mh,$running);}while($running>0); part, until both curl handles are done.. and i believe a solution is curl_multi_select ; there already is example codes on curl_multi_exec / curl_multi_init that use curl_multi_select to do non-busy-waiting (or whatever it's called, idk), maybe copy&paste the example code from 1 of those? Expected result: ---------------- small cpu usage Actual result: -------------- high cpu usage -- Edit bug report at https://bugs.php.net/bug.php?id=64191&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64191&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64191&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64191&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=64191&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=64191&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=64191&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=64191&r=needscript Try newer version: https://bugs.php.net/fix.php?id=64191&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=64191&r=support Expected behavior: https://bugs.php.net/fix.php?id=64191&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=64191&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=64191&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=64191&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64191&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=64191&r=dst IIS Stability: https://bugs.php.net/fix.php?id=64191&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=64191&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=64191&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=64191&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=64191&r=mysqlcfg

« previous php.doc.bugs (#9514) next »