doufeiqiong3515 2016-06-23 18:57
浏览 48

等到在PHP脚本中完成Perl脚本的执行

I am trying to execute perl script inside php script. Although it is running but only for short duration. How to increase the time-limit so that the execution of perl script is finished until the final php script is called of ?

I am running php script on the localhost.

Here is the code :

<?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);

?>
  • 写回答

1条回答 默认 最新

  • dongxiaoying5882 2016-06-23 19:38
    关注

    Looks like you've over-complicated the problem. Unless I'm missing something, your entire code can be replaced by a single line

    <?php
    exec("perl -f script.pl  ");
    ?>
    

    as this will have the same effect as forking and then immediately waiting for the child process to finish.

    To avoid the page timing out before the perl script is finished, simply add set_time_limit(0) before calling exec:

    <?php
    set_time_limit(0);
    exec("perl -f script.pl  ");
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器