3

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.

3
  • 1
    Have you tried capturing/logging the standard output / standard error output from the shell execution? Commented Feb 1, 2012 at 18:07
  • Hi! Sorry for my poor knowledge, how i do that? Commented Feb 1, 2012 at 19:22
  • I solved! Fosco tell me to get the error output and got it! Stupid bug.. i was trying to access one file off other directory. Sorry guys! Thanks for help me! Commented Feb 1, 2012 at 19:45

1 Answer 1

4

Try using the absolute path to php.

    echo(shell_exec("nohup /usr/bin/php get_tweets.php > /dev/null & echo $!"));
Sign up to request clarification or add additional context in comments.

3 Comments

Only returns the PID (labs.lung.com.br/ztbot/bin/v2/php/sistema.php), but the process doesnt run.
Can you post the output of the following code: $cmd = 'set'; echo "<pre>".shell_exec($cmd)."</pre>";
Cool! Glad you figured it out! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.