我正在尝试在php脚本中执行perl脚本。虽然它正在运行但只持续很短的时间。 如何增加时间限制,以便完成perl脚本的执行,直到调用最终的PHP脚本?
我在localhost上运行php脚本。
以下是代码:
<?php
$maxChildren = 1;
$pids = array();
$pid = pcntl_fork();
if ($pid) { // Parent
if ($pid < 0) {
// Unable to fork process, handle error here
continue;
} else {
$pids[$pid] = $pid;
}
} else {
exec("perl -f script.pl ");
exit(0);
}
while(pcntl_waitpid(0, $status) != -1);
?>
答案 0 :(得分:1)
看起来你已经过度复杂了这个问题。除非我遗漏了某些内容,否则您的整个代码可以替换为一行
<?php
exec("perl -f script.pl ");
?>
因为这将与分叉具有相同的效果,然后立即等待子进程完成。
要在perl脚本完成之前避免页面超时,只需在调用exec之前添加set_time_limit(0)
:
<?php
set_time_limit(0);
exec("perl -f script.pl ");
?>