Run php script on background in PHP with nohup CLI

守給你的承諾、 提交于 2019-12-01 06:13:46

问题


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.

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 &

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.

I list the files in that folder: exec("ls"); And they are in the same level...

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.


回答1:


Try using the absolute path to php.

    echo(shell_exec("nohup /usr/bin/php get_tweets.php > /dev/null & echo $!"));


来源:https://stackoverflow.com/questions/9100872/run-php-script-on-background-in-php-with-nohup-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!