dongqiao5573 2009-11-21 19:39
浏览 80
已采纳

在php中运行并忘记系统调用

So I am trying to execute some script from my php code. That lives in page blah.php

<?php
     // ....
     // just basic web site that allows upload of file...
?>

Inside I use system call

if (system("blah.pl arg1") != 0)
{
   print "error
";
}
else
{
   print "working on it..you will receive e-mail at completion
";
}

Works great but it waits until it completes until it prints working on it. I am aware that I am calling perl script from php not a typo.

How can I just start program execution and let it complete in background. The blah.pl script handles e-mail notification.

Anyone?

Thanks I appreciate it

  • 写回答

4条回答 默认 最新

  • dpwgzi7987 2009-11-21 19:44
    关注

    From system function documentation:

    Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

    Simply redirect the output of your Perl script and PHP should be able to run without having to wait for the script to finish.

    system("blah.pl arg1 > /dev/null 2>&1 &");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程