Bug #72202 [Opn->Ver]: curl_close don't close cURL handle on curl_multi
| From: | krakjoe@php.net | Date: | Sat, 14 May 2016 07:26:48 +0000 |
| Subject: | Bug #72202 [Opn->Ver]: curl_close don't close cURL handle on curl_multi | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201090@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72202&edit=1
ID: 72202
Updated by: krakjoe@php.net
Reported by: torsten dot burschka at gmail dot com
Summary: curl_close don't close cURL handle on curl_multi
-Status: Open
+Status: Verified
Type: Bug
Package: cURL related
Operating System: ArchLinux
PHP Version: 7.0.6
-Assigned To:
+Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
Broken commit:
commit 3ba4f8263d7940312668f4c364c988a67be2461a
Author: Dmitry Stogov <dmitry@zend.com>
Date: Tue May 13 16:00:44 2014 +0400
Fixed curl_close() behavior
I'm not sure what this commit is supposed to fix, it looks wrong to me.
Previous Comments:
------------------------------------------------------------------------
[2016-05-11 21:57:37] torsten dot burschka at gmail dot com
Description:
------------
A cURL ressource seem to be not closed correctly after using it with curl_multi_exec. According to
this answer on stackoverflow http://stackoverflow.com/a/23007037/363323 the
handle should be removed since the internal counter should be 0 after curl_multi_remove_handle and
curl_close should do the rest...
Test script:
---------------
$ch1 = curl_init();
$ch2 = curl_init();
curl_setopt($ch1, CURLOPT_URL, 'http://lxr.php.net/');
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_URL, 'http://www.php.net/');
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$cmh = curl_multi_init();
curl_multi_add_handle($cmh, $ch1);
curl_multi_add_handle($cmh, $ch2);
$status = curl_multi_exec($cmh, $active);
$innerSleepInt = $outerSleepInt = 1;
while ($active && ($status === CURLM_OK || $status === CURLM_CALL_MULTI_PERFORM)) {
usleep((int)$outerSleepInt);
$outerSleepInt = (int) max(1, $outerSleepInt * 1.1);
$multiSelect = curl_multi_select($cmh, 0);
/* @see https://bugs.php.net/bug.php?id=63411 */
if ($multiSelect === -1) {
usleep(100000);
}
/* @see https://curl.haxx.se/libcurl/c/libcurl-errors.html
*/
if ($multiSelect >= CURLM_CALL_MULTI_PERFORM) {
do {
$status = curl_multi_exec($cmh, $active);
usleep((int) $innerSleepInt);
$innerSleepInt = (int) max(1, $innerSleepInt * 1.1);
} while ($status === CURLM_CALL_MULTI_PERFORM);
$innerSleepInt = 1;
}
while ($done = curl_multi_info_read($cmh)) {
$ch = $done['handle'];
curl_multi_getcontent($ch);
curl_multi_remove_handle($cmh, $ch);
curl_close($ch);
echo is_resource($ch); // this should be return false
}
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72202&edit=1