douzi8548 2011-08-10 14:48
浏览 96
已采纳

多个exec命令php [复制]

Possible Duplicate:
php in background exec() function

I am trying to run two exec commands from PHP. One is a script that might run for a few minutes and there can only be once instance of it. The second exec just checks if the first process is running and either lets you run it again or redirects you. The code is something like this.

This is the main process

$command = '/home/user/active/Nem-Swd.elf 30 > /dev/null 2>&1 & echo $!';

This is the process that checks if the other one is running already.

exec("ps ax | grep $name 2>&1", $output);

I know that in the php API it says :

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.

But I don't understand what that implies.

  • 写回答

1条回答 默认 最新

  • dongmao4486 2011-08-10 14:59
    关注

    It means that if you run the exec command without re-routing its output, your current PHP script will wait for that command to finish before terminating the script. Since you are routing the output to standard out, I believe you should be ok. If you just ran exec($commandJob) you then would run into this problem.


    Seems that this question has already been answered:
    php in background exec() function

    At a minimum (for example) you need to do this to make it run in the background:
    exec("php test.php &");


    There are other ways to start processes that might be worth looking into as well: http://www.php.net/manual/en/book.pcntl.php
    http://php.net/manual/en/function.popen.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!