Note that there are some explanatory texts on larger screens.

plurals
  1. POAdvanced PHP: Configure an onBefore and/or onAfter callback for a cURL handle?
    primarykey
    data
    text
    <p>I'm working with the cURL implementation in PHP and leveraging curl_multi_init() and curl_multi_exec() to execute batches of requests in parallel. I've been doing this for a while, and understand this piece of it.</p> <p>However, the request bodies contain a <em>signature</em> that is calculated with a timestamp. From the moment this signature is generated, I have a limited window of time to make the request before the server will reject the request once it's made. Most of the time this is fine. However, in some cases, I need to do large uploads (5+ GB).</p> <p>If I batch requests into a pool of 100, 200, 1000, 20000, or anything in-between, and I'm uploading large amounts of data to the server, the initial requests that execute will complete successfully. Later requests, however, won't have started until after the timestamp in the signature expires, so the server rejects those requests out-of-hand.</p> <p>The current flow I'm using goes something like this:</p> <ol> <li>Do any processing ahead of time.</li> <li>Add the not-yet-executed cURL handles to the batch.</li> <li>Let cURL handle executing all of the requests.</li> <li>Look at the data that came back and parse it all.</li> </ol> <p>I'm interested in finding a way to execute a callback function that can generate a signature on-demand and update the request body at the moment that PHP/cURL goes to execute that particular request. I know that you can bind a callback function to a cURL handle that will execute repeatedly while the request is happening, and you have access to the cURL handle all along the way.</p> <p>So my question is this: Is there any way to configure an onBefore and/or onAfter callback for a cURL handle? Something that can execute immediately before the cURL executes the request, and then something that can execute immediately after the response comes back so that the response data can be parsed.</p> <p>I'd like to do something a bit more event oriented, like so:</p> <ol> <li>Add a not-yet-executed cURL handle to the batch, assigning a callback function to execute when cURL (not myself) executes the request (both before and after).</li> <li>Take the results of the batch request and do whatever I want with the data.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload