Skip to content

Commit

Permalink
Fix CURL forced type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Nov 27, 2020
1 parent 0b78f89 commit 1eb3dbb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ezimuel/ringphp",
"name": "sy-records/ringphp",
"description": "Fork of guzzle/RingPHP (abandoned) to be used with elasticsearch-php",
"license": "MIT",
"authors": [
Expand All @@ -9,6 +9,10 @@
"homepage": "https://github.com/mtdowling"
}
],
"support": {
"issues": "https://github.com/lufei/ringphp/issues",
"source": "https://github.com/lufei/ringphp"
},
"require": {
"php": ">=5.4.0",
"ezimuel/guzzlestreams": "^3.0.1",
Expand All @@ -31,6 +35,10 @@
"GuzzleHttp\\Tests\\Ring\\": "tests/"
}
},
"replace": {
"guzzlehttp/ringphp": "self.version",
"ezimuel/ringphp": "self.version"
},
"scripts": {
"test": "make test",
"test-ci": "make coverage"
Expand Down
4 changes: 2 additions & 2 deletions src/Client/CurlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private function checkoutEasyHandle()

// Add a new handle
$handle = curl_init();
$id = (int) $handle;
$id = Core::handle2Id($handle);
$this->handles[$id] = $handle;
$this->ownedHandles[$id] = true;

Expand All @@ -115,7 +115,7 @@ private function checkoutEasyHandle()

private function releaseEasyHandle($handle)
{
$id = (int) $handle;
$id = Core::handle2Id($handle);
if (count($this->ownedHandles) > $this->maxHandles) {
curl_close($this->handles[$id]);
unset($this->handles[$id], $this->ownedHandles[$id]);
Expand Down
14 changes: 14 additions & 0 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,18 @@ public static function getDebugResource($value = null)
return fopen('php://output', 'w');
}
}

public static function handle2Id($handle)
{
if (is_resource($handle)) {
$id = (int) $handle;
} else {
if (PHP_VERSION_ID < 70200) {
$id = spl_object_hash($handle);
} else {
$id = spl_object_id($handle);
}
}
return $id;
}
}

0 comments on commit 1eb3dbb

Please sign in to comment.