8000 [HttpClient] Support for cURL handler objects by derrabus · Pull Request #37379 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpClient] Support for cURL handler objects #37379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HttpClient] Support for cURL handler objects.
  • Loading branch information
derrabus authored and fabpot committed Jun 24, 2020
commit 7ccc2e1f28e62acaaa27ab2d6bc44daa0ee67310
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpClient/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public function reset()
$this->multi->dnsCache->evictions = $this->multi->dnsCache->evictions ?: $this->multi->dnsCache->removals;
$this->multi->dnsCache->removals = $this->multi->dnsCache->hostnames = [];

if (\is_resource($this->multi->handle)) {
if (\is_resource($this->multi->handle) || $this->multi->handle instanceof \CurlMultiHandle) {
if (\defined('CURLMOPT_PUSHFUNCTION')) {
curl_multi_setopt($this->multi->handle, CURLMOPT_PUSHFUNCTION, null);
}
Expand All @@ -347,7 +347,7 @@ public function reset()
}

foreach ($this->multi->openHandles as [$ch]) {
if (\is_resource($ch)) {
if (\is_resource($ch) || $ch instanceof \CurlHandle) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, why are these is_resource checks necessary in the first place? Are they getting closed somehow without being removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question indeed. I haven't found a reason why $ch should be anything else than a cURL handle. And the tests still pass if I remove the two guard clauses.

Maybe @nicolas-grekas knows more about why we need(ed?) this check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen strange things happen at destructing/shutdown time, this might be related.

curl_setopt($ch, CURLOPT_VERBOSE, false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
final class CurlClientState extends ClientState
{
/** @var resource */
/** @var \CurlMultiHandle|resource */
public $handle;
/** @var PushedResponse[] */
public $pushedResponses = [];
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/HttpClient/Response/CurlResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ final class CurlResponse implements ResponseInterface
private $debugBuffer;

/**
* @param \CurlHandle|resource|string $ch
*
* @internal
*/
public function __construct(CurlClientState $multi, $ch, array $options = null, LoggerInterface $logger = null, string $method = 'GET', callable $resolveRedirect = null, int $curlVersion = null)
{
$this->multi = $multi;

if (\is_resource($ch)) {
if (\is_resource($ch) || $ch instanceof \CurlHandle) {
unset($multi->handlesActivity[(int) $ch]);
$this->handle = $ch;
$this->debugBuffer = fopen('php://temp', 'w+');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ trait ResponseTrait
'canceled' => false,
];

/** @var resource */
/** @var object|resource */
private $handle;
private $id;
private $timeout = 0;
Expand Down
0