【问题标题】:PHP fork without having child inherit the parent's file descriptors?PHP fork 没有子继承父文件描述符?
【发布时间】:2010-09-19 15:39:31
【问题描述】:

我正在尝试使用反引号运算符运行 shell 命令,但是子进程继承 php 的打开文件描述符这一事实是有问题的。有没有办法防止这种情况发生?

我正在运行 PHP 5.1.2

【问题讨论】:

    标签: php process


    【解决方案1】:

    我真正知道的唯一方法是让孩子们在分叉后打开自己的资源。

    这里有一个相当不错的关于 pcntl 的教程:

    http://www.hackingwithphp.com/16/0/0/miscellaneous-topics http://www.hackingwithphp.com/16/1/4/duplication-of-resources-when-forking

    【解决方案2】:

    这对我有用:

    $cmd_to_run = escapeshellarg('/path/to/file --args');
    `echo $cmd_to_run | /bin/at now`;
    

    将“/path/to/file --args”部分替换为您要运行的命令。 'at' 命令使用您的 cron 守护程序来安排任务。

    【讨论】:

      猜你喜欢
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 2017-11-30
      • 2014-02-26
      • 2015-09-14
      • 2012-10-16
      • 2011-10-02
      • 2012-07-28
      相关资源
      最近更新 更多