I have two script, request.php send a post request to receiver.php via PHP CURL, and I would like to close the connection and response to CURL immediately and continue running my script in background.
Script below was unable to achieve my expectation, appreciate that someone able to provide a proper way to do this. Thank you so much~~~
request.php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://example.com/receiver.php',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query($params)
));
curl_exec($curl);
curl_close($curl);
receiver.php
ob_end_clean();
header("Connection: close");
ignore_user_abort(true);
ob_start();
echo('Text the user will see');
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush();
flush();
sleep(30);
echo('Text user will never see');