我有两个脚本,request.php通过PHP CURL向receiver.php发送一个post请求,我想立即关闭连接并响应CURL并继续在后台运行我的脚本。
下面的脚本无法实现我的期望,感谢能够提供正确方法的人。非常感谢你~~~
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');