这取决于您的实现。PHP中99%的函数被阻塞。这意味着在当前函数完成之前,处理不会继续。但是,如果函数包含循环,则可以添加自己的代码,以便在满足特定条件后中断循环。
像这样:
foreach ($array as $value) {
perform_task($value);
}
function perform_task($value) {
$start_time = time();
while(true) {
if ((time() - $start_time) > 300) {
return false; // timeout, function took longer than 300 seconds
}
// Other processing
}
}
另一个无法中断处理的示例:
foreach ($array as $value) {
perform_task($value);
}
function perform_task($value) {
// preg_replace is a blocking function
// There's no way to break out of it after a certain amount of time.
return preg_replace('/pattern/', 'replace', $value);
}