在后台运行PHP脚本PHP中的nohup CLI [英] Run php script on background in PHP with nohup CLI
问题描述
I,M试图在后台运行一个叫做PHP脚本。但其没有工作......我只能直接从SSH终端上运行。使用相同的CLI脚本。
I,m trying to run one php script in background. But its no working... I can only run directly from the ssh terminal. Using the same cli script.
在终端,首先我访问路径: CD labs.lung.com.br/ztbot/bin/v2/php
在那之后,我在后台运行我的脚本:的nohup PHP get_tweets.php>的/ dev / null的&安培;
On the terminal, first i access the path: cd labs.lung.com.br/ztbot/bin/v2/php
After that, i run my script in background: nohup php get_tweets.php > /dev/null &
和它的作品!但是,当我尝试做我的PHP脚本,同样的事情: EXEC(nohup的PHP get_tweets.php>的/ dev / null的&安培;);
不起作用。这两个文件都在同一个目录。
And it works! But, when i try to do the same thing with my php script: exec("nohup php get_tweets.php > /dev/null &");
doesnt work. Both files are in the same directory.
我列出文件夹中的文件: EXEC(LS);
键,它们是在同一水平线上...
I list the files in that folder: exec("ls");
And they are in the same level...
直到PID其返回,当我运行:回声(了shell_exec(!nohup的PHP get_tweets.php>的/ dev / null的&安培;回声$));
Until PID its returned, when i run: echo(shell_exec("nohup php get_tweets.php > /dev/null & echo $!"));
但由于某些原因脚本犯规运行。
But for some reason the script doesnt run.
推荐答案
尝试使用到PHP的绝对路径。
Try using the absolute path to php.
echo(shell_exec("nohup /usr/bin/php get_tweets.php > /dev/null & echo $!"));
这篇关于在后台运行PHP脚本PHP中的nohup CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!