Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run php script on background in PHP with nohup 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.

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.

like image 912
Evandro Eisinger Avatar asked Jun 18 '26 22:06

Evandro Eisinger


1 Answers

Try using the absolute path to php.

    echo(shell_exec("nohup /usr/bin/php get_tweets.php > /dev/null & echo $!"));
like image 168
seanbreeden Avatar answered Jun 20 '26 12:06

seanbreeden