Skip to content

Commit

Permalink
Curl 使用完连接后执行 curl_reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Mar 31, 2022
1 parent 701517d commit 2061f97
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/YurunHttp/Handler/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function close()
{
if ($this->poolIsEnabled)
{
curl_reset($this->handler);
CurlHttpConnectionManager::getInstance()->release($this->poolKey, $this->handler);
}
else
Expand Down Expand Up @@ -229,11 +230,15 @@ public function send(&$request)
}
finally
{
if ($poolIsEnabled && $this->handler)
if ($this->handler)
{
// @phpstan-ignore-next-line
$httpConnectionManager->release($this->poolKey, $this->handler);
$this->handler = null;
curl_reset($this->handler);
if ($poolIsEnabled)
{
// @phpstan-ignore-next-line
$httpConnectionManager->release($this->poolKey, $this->handler);
$this->handler = null;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/YurunHttp/Traits/THandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function parseRedirectLocation($location, $currentUri)
{
$uri = $currentUri;
$path = $currentUri->getPath();
if('/' !== substr($path, -1, 1))
if ('/' !== substr($path, -1, 1))
{
$path = $path . '/';
}
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/HttpRequestTest/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,21 @@ public function testHead()
$this->assertResponse($response);
});
}

/**
* @see https://github.com/Yurunsoft/YurunHttp/issues/19
*
* @return void
*/
public function testBug19()
{
$this->call(function () {
$http = new HttpRequest();
$response = $http->head('https://www.baidu.com');
$this->assertResponse($response);
$response = $http->get('https://www.baidu.com');
$this->assertResponse($response);
$this->assertTrue('' != $response->body());
});
}
}

0 comments on commit 2061f97

Please sign in to comment.