Evandro Eisinger
Evandro Eisinger

Reputation: 55

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.

Upvotes: 3

Views: 11003

Answers (1)

seanbreeden
seanbreeden

Reputation: 6097

Try using the absolute path to php.

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

Upvotes: 4

Related Questions