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
[9.x] Fix HTTP client pool #43789
[9.x] Fix HTTP client pool #43789
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,24 +5,17 @@ | |
use GuzzleHttp\Utils; | ||
|
||
/** | ||
* @mixin \Illuminate\Http\Client\Factory | ||
* @mixin \Illuminate\Http\Client\PendingRequest | ||
*/ | ||
class Pool | ||
{ | ||
/** | ||
* The factory instance. | ||
* | ||
* @var \Illuminate\Http\Client\Factory | ||
* @var \Illuminate\Http\Client\PendingRequest | ||
*/ | ||
protected $factory; | ||
|
||
/** | ||
* The handler function for the Guzzle client. | ||
* | ||
* @var callable | ||
*/ | ||
protected $handler; | ||
|
||
/** | ||
* The pool of requests. | ||
* | ||
|
@@ -33,18 +26,18 @@ class Pool | |
/** | ||
* Create a new requests pool. | ||
* | ||
* @param \Illuminate\Http\Client\Factory|null $factory | ||
* @param \Illuminate\Http\Client\PendingRequest|null $factory | ||
* @return void | ||
*/ | ||
public function __construct(Factory $factory = null) | ||
public function __construct(PendingRequest $factory = null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a major breaking change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only if people are directly creating pools without going through the If you want, I can split this PR into 2 PR:
This way, no breaking changes in PR 1 and then you can decide what to do with PR 2. I just need PR 1 for my use-case at the moment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just one question, this change of yours won't break the multiCurlHandler functionality where all pending requests are executed concurrently, right? |
||
{ | ||
$this->factory = $factory ?: new Factory(); | ||
|
||
if (method_exists(Utils::class, 'chooseHandler')) { | ||
$this->handler = Utils::chooseHandler(); | ||
$handler = Utils::chooseHandler(); | ||
} else { | ||
$this->handler = \GuzzleHttp\choose_handler(); | ||
$handler = \GuzzleHttp\choose_handler(); | ||
} | ||
|
||
$this->factory = ($factory ?? new Factory())->async()->setHandler($handler); | ||
} | ||
|
||
/** | ||
|
@@ -55,17 +48,17 @@ public function __construct(Factory $factory = null) | |
*/ | ||
public function as(string $key) | ||
{ | ||
return $this->pool[$key] = $this->asyncRequest(); | ||
return $this->pool[$key] = $this->newPendingAsyncRequest(); | ||
} | ||
|
||
/** | ||
* Retrieve a new async pending request. | ||
* | ||
* @return \Illuminate\Http\Client\PendingRequest | ||
*/ | ||
protected function asyncRequest() | ||
protected function newPendingAsyncRequest() | ||
{ | ||
return $this->factory->setHandler($this->handler)->async(); | ||
return clone $this->factory; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to return a request instance? |
||
} | ||
|
||
/** | ||
|
@@ -87,6 +80,6 @@ public function getRequests() | |
*/ | ||
public function __call($method, $parameters) | ||
{ | ||
return $this->pool[] = $this->asyncRequest()->$method(...$parameters); | ||
return $this->pool[] = $this->newPendingAsyncRequest()->$method(...$parameters); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a request, why is the variable $factory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually a PendingRequest template that will be cloned in each pool request. I kept the name since it's like a template for each created request. Lmk if there's a more adequate name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @taylorotwell, this is highly confusing. We shouldn't change all of this imo in 9.x but in 10.x at the earliest (if we're going to do this).