php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72202 curl_close don't close cURL handle on curl_multi
Submitted: 2016-05-11 21:57 UTC Modified: 2016-05-14 07:26 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: torsten dot burschka at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: cURL related
PHP Version: 7.0.6 OS: ArchLinux
Private report: No CVE-ID: None
 [2016-05-11 21:57 UTC] 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
            }
        }



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-14 07:26 UTC] krakjoe@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: dmitry
 [2016-05-14 07:26 UTC] krakjoe@php.net
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.
 [2016-06-07 11:41 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5b81f9d92ec6c7cd093c06ca88a1e0a31f8fe364
Log: Fixed bug #72202 (curl_close doesn't close cURL handle) Now curl_close() forces connection close, independently of other links to the same resource.
 [2016-06-07 11:41 UTC] dmitry@php.net
-Status: Verified +Status: Closed
 [2016-06-22 05:58 UTC] krakjoe@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5b81f9d92ec6c7cd093c06ca88a1e0a31f8fe364
Log: Fixed bug #72202 (curl_close doesn't close cURL handle) Now curl_close() forces connection close, independently of other links to the same resource.
 [2016-07-20 11:30 UTC] davey@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=5b81f9d92ec6c7cd093c06ca88a1e0a31f8fe364
Log: Fixed bug #72202 (curl_close doesn't close cURL handle) Now curl_close() forces connection close, independently of other links to the same resource.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 20:01:29 2024 UTC