stil/curl-easy

Queuing of CURLOPT_POSTFIELDS

Closed this issue · 4 comments

Make it possible to queue requests with arguments passed though CURLOPT_POSTFIELDS. This would allow packages, e.g., XML, to be queued and sent as a HTTP POST.

stil commented

Can you share some details? You cannot send requests in parallel if they need to be sent in some order.

Hi. Yeah, I'm looking to send a HTTP POST to a site to upload xml data. The data needs to be sent thru using CURLOPT_POSTFIELDS. However, the data does not need to be send in any particular order as the xml packages are distinct and mutually exclusive.

The stumbling block that i saw is that you can queue requests, but you can't queue packages sent thru CURLOPT_POSTFIELDS, unless I'm mistaken.. Thanks

stil commented

I'm not really sure if you can't just:

<?php
$queue = new \cURL\RequestsQueue();
$queue->getDefaultOptions()
    ->set(CURLOPT_POST, true) // All requests will be POST
    ->set(CURLOPT_TIMEOUT, 5)
    ->set(CURLOPT_RETURNTRANSFER, true);

$queue->addListener('complete', function (\cURL\Event $event) {
    // something to do with response
});

$request = new \cURL\Request('http://example1');
$request->getOptions()->set(CURLOPT_POSTFIELDS, array('foo' => 'bar'));
$queue->attach($request);

$request = new \cURL\Request('http://example2');
$request->getOptions()->set(CURLOPT_POSTFIELDS, array('abc' => 'def'));
$queue->attach($request);

$queue->send();

HI. Thanks for the suggestion. I'll take a look