【问题标题】:Shell_exec nohup with nohup.outShell_exec nohup 与 nohup.out
【发布时间】:2015-04-23 00:01:02
【问题描述】:

执行此代码:

shell_exec('nohup command&');

或者这个

shell_exec('nohup command > /path/to/nohup.out 2>&1&');

但是在这两种情况下都没有 nohup.out。如何通过 php 使用 nohup.out 运行 nohup?

【问题讨论】:

  • 第二个绝对应该已经创建了该文件(无论nohupcommand 实际上是否实际运行)。你确定它没有创建文件吗? (或者你的意思是文件是空的?)
  • 您运行它的服务器是否允许shell_exec() 运行?

标签: php shell nohup


【解决方案1】:

shell_exec('nohup command > /path/to/nohup.out 2>&1&');

这条线会起作用。只需确保您对输出文件夹具有写入权限即可。考虑您的输出文件夹是 /usr/nohup-out

ls -l /usr/nohup-out

它应该具有写入、读取和执行权限 (rwx)。如果没有,请执行以下操作:

sudo chmod -R 777 /usr/nohup-out

现在,尝试执行 php 文件。它应该在/usr/nohup-out 文件夹中创建一个nohup 文件。

示例脚本和结果:

1.日期.php:

<?php
shell_exec('nohup date > /usr/nohup-out/nohup.out 2>&1&');
?>

2。从终端执行php:

php date.php

3. nohup.out 执行后的内容

2015 年 4 月 23 日星期四 11:30:28 IST

【讨论】:

  • > 只要确保您对输出文件夹具有写入权限 - 这就是解决方案,谢谢。
猜你喜欢
  • 2011-06-23
  • 2011-12-22
  • 1970-01-01
  • 2019-01-17
  • 2014-08-30
  • 1970-01-01
  • 2012-05-11
  • 2018-02-15
相关资源
最近更新 更多