Linux背景PHP过程

好吧,这似乎很奇怪。 当我在命令行运行一个php脚本时,最后在后台运行它,它会立即停止。 我在另一台服务器上尝试了它,并按预期工作; 该作业正在后台运行。

PHP

 #!/usr/bin/php <?php sleep (5); 

在服务器1上输出

 [mk@li89-44 html]# ./test.php & [1] 4938 [mk@li89-44 html]# jobs [1]+ Running ./test.php & 

在服务器2上输出

 [mk@dev html]# ./test.php & [1] 4938 [mk@dev html]# jobs [1]+ Stopped ./test.php & 

在服务器2上,我可以像这样在后台得到它:

 [mk@dev html]$ ./test.php ctrl + z [1]+ Stopped ./test.php [mk@dev html]$ bg [1]+ ./test.php & [mk@dev html]$ jobs [1]+ Running ./test.php 

同样在服务器2上,如果我做了像wget "http://fileserver.com/largefile.gz" &这样的东西wget "http://fileserver.com/largefile.gz" &它进入bg按预期运行。 在服务器2上运行nohup ./test.php &也按预期工作。

两台服务器都运行centos,不同的版本,以及不同版本的php。 我不知道,如果这是相关的,或者如果这可以通过jobs方式, fgbglinux上工作的方式解释。

如果你看一下这个过程的一个阶段,你可以看到PHP总是初始化terminal,这需要等待PHP来控制terminal:

 ioctl(0, TCSETSW, {B38400 opost isig icanon echo ...}) = ? ERESTARTSYS --- {si_signo=SIGTTOU, si_code=SI_KERNEL} (Stopped (tty output)) --- --- Stopped (tty output) by SIGTTOU --- 

一个简单的解决方法:

./test.php> / dev / null&

你确定你已经安装了php-cli软件包吗?

检查/usr/bin/php是否是二进制文件的path,不同的版本使用不同的path。