Replies: 5 comments 1 reply
-
Currently this isn't possible. If the code to enable this is easy, I'd accept a PR with tests and an updated readme. |
Beta Was this translation helpful? Give feedback.
-
I did it for myself but I dont think that you would do that because it needs to extend Pool class of guzzle to accomplish that i extend Pool class and changed its construct to add my code to alter request options. |
Beta Was this translation helpful? Give feedback.
-
changes to startCrawlingQueue function
changes to construct of Pool class
|
Beta Was this translation helpful? Give feedback.
-
I use this opportunity to thank you for your great packages 🌹 |
Beta Was this translation helpful? Give feedback.
-
For your current needs there is already a facility in place in the Guzzle code: Middlewares. <?php
namespace App\Infrastructure\Network;
use ArrayIterator;
use GuzzleHttp\Promise\PromiseInterface;
use InfiniteIterator;
use Iterator;
use Psr\Http\Message\RequestInterface;
class InterfacesMiddleware
{
/** @var callable */
private $nextHandler;
private Iterator $interfaces;
public function __construct(
callable $nextHandler,
string ...$interfaces
) {
$this->nextHandler = $nextHandler;
$this->interfaces = new InfiniteIterator(new ArrayIterator($interfaces));
$this->interfaces->rewind();
}
public function __invoke(RequestInterface $request, array $options): PromiseInterface
{
$fn = $this->nextHandler;
$options['curl'][CURLOPT_INTERFACE] = $this->interfaces->current();
$this->interfaces->next();
return $fn($request, $options);
}
} Now in Crawler construction time: $handler = HandlerStack::create(new CurlMultiHandler());
$handler->push(
function (callable $handler) use ($interfaces){
return new InterfacesMiddleware($handler, ...$interfaces);
},
'Interfaces manager or any other name'
);
$options = [
'handler' => $handler,
];
$crawler = Crawler::create($options); |
Beta Was this translation helpful? Give feedback.
-
Hello
Is there any ways to set separate option for each request?
for example I need to dispatch request across all of my server IP addresses by setting CURLOPT_INTERFACE, so I will need to set this option before sending each request.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions