PHP curl加1ms超时-足够用于目标的时间';是否忽略用户中止(true)以激活?
我试图通过一个几乎立即超时的curl请求启动一个长时间运行脚本的“异步”php作业。我知道在不同的堆栈上存在更好的解决方案,但这似乎是一个常见的建议,当香草php是所有可用的PHP curl加1ms超时-足够用于目标的时间';是否忽略用户中止(true)以激活?,php,curl,asynchronous,timeout,Php,Curl,Asynchronous,Timeout,我试图通过一个几乎立即超时的curl请求启动一个长时间运行脚本的“异步”php作业。我知道在不同的堆栈上存在更好的解决方案,但这似乎是一个常见的建议,当香草php是所有可用的 $c = curl_init(); curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_FOLLOWLOCATION, true); // Follow the redirects (needed for mod_rewrite) curl_setopt
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true); // Follow the redirects (needed for mod_rewrite)
curl_setopt($c, CURLOPT_HEADER, false); // Don't retrieve headers
curl_setopt($c, CURLOPT_NOBODY, true); // Don't retrieve the body
curl_setopt($c, CURLOPT_RETURNTRANSFER, true); // Return from curl_exec rather than echoing
// Timeout super fast once connected, so it goes into async.
curl_setopt( $c, CURLOPT_TIMEOUT_MS, 1 );
return curl_exec( $c );
在target$url
中,我定义了一个脚本,该脚本应该忽略用户中止,然后执行自己的操作
ob_start();
ignore_user_abort(true);
set_time_limit(0);
echo "OK";
ob_flush();
flush();
// wait 5s to help debug
sleep(5);
// processing stuff
因此,当CURLOPT\u TIMEOUT\u MS
设置为1ms
时,脚本永远不会运行。当它设置为100ms
时,它仍然不会运行。当它设置为500ms
时,它以预期的行为运行(父脚本放弃并在~500ms后返回,我的脚本的预期逻辑在5s
后执行)
我是否做错了什么,或者简单的回答是,即使是脚本顶部的ignore\u user\u abort()
也需要一定的时间来执行