I'm trying to send off a request to resize an image to an API I made. After I send the request, I serve up an un-resized image while I wait for the resized image to be made. Is there a way make a curl request but then not wait for the response so I can quickly serve up an image?
This is my current (blocking) solution:
$mh_curl = curl_multi_init();
$ch = curl_init();
//POST request
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_multi_add_handle($mh_curl, $ch);
$running = NULL;
//execute curl handles
do {
curl_multi_exec($mh_curl, $running);
curl_multi_select($mh_curl);
} while ($running > 0);
//close the handles
curl_multi_remove_handle($mh_curl, $ch);
curl_multi_close($mh_curl);
Try:
$cmd = 'curl -s "http://my.domain/script.php"';
exec($cmd . " > /dev/null &");
This will lead the curl result to nirvana
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With