php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50477 curl_close() does not delete cURL handle as expected
Submitted: 2009-12-15 11:05 UTC Modified: 2010-01-05 10:44 UTC
From: pcdinh at gmail dot com Assigned:
Status: Not a bug Package: cURL related
PHP Version: 5.2.11 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
23 - 17 = ?
Subscribe to this entry?

 
 [2009-12-15 11:05 UTC] pcdinh at gmail dot com
Description:
------------
As stated at http://php.net/manual/en/function.curl-close.php an invocation to curl_close($ch) will 

"Closes a cURL session and frees all resources. The cURL handle, ch , is also deleted. "

However, it does not.

Curl seems to work differently than other functions that produce a resource as well. Curl does not pass by reference implicitly

For example:

// create an image resource
$image = imagecreate(100, 100);
$im = new stdClass();
$im->res = $image; // pass by reference
var_dump($image);
var_dump($im->res);
imagedestroy($image);
var_dump($image); // will print resource(4) of type (Unknown)
var_dump($im->res); // will print resource(4) of type (Unknown)

After calling imagedestroy($image), $image and $im->res are deleted



Reproduce code:
---------------
$s = curl_init();
$im = new stdClass();
$im->res = $s; // resource is passed by reference
var_dump($s); // will print: resource(5) of type (curl) 
var_dump($im->res); // will print: resource(5) of type (curl)
curl_close($s);
var_dump($s);
var_dump($im->res);

Expected result:
----------------
$s = curl_init();
$im = new stdClass();
$im->res = $s; // resource is passed by reference
var_dump($s); // will print: resource(5) of type (curl) 
var_dump($im->res); // will print: resource(5) of type (curl)
curl_close($s);
var_dump($s); // (expected): resource(5) of type (Unknown)
var_dump($im->res); // (expected): resource(5) of type (Unknown)

Actual result:
--------------
$s = curl_init();
$im = new stdClass();
$im->res = $s; // resource is actually passed by value
var_dump($s); // will print: resource(5) of type (curl) 
var_dump($im->res); // will print: resource(5) of type (curl)
curl_close($s);
var_dump($s); // (actual): resource(5) of type (curl)
var_dump($im->res); // (actual): resource(5) of type (curl)

$s becomes invalid but $im->res is still valid for subsequent operations.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-15 11:34 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-12-23 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2010-01-05 10:31 UTC] pcdinh at gmail dot com
This bug still exists in 5.2.12
 [2010-01-05 10:36 UTC] pcdinh at gmail dot com
Sorry, I have just tested it again in PHP 5.1.12 and it works
 [2010-01-05 10:44 UTC] pajoye@php.net
works as expected.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu May 06 16:01:25 2021 UTC