The script works!
First I type this in my CLI: php worker.php >>/home/xxx/log 2>&1
Then, I want it to run as its own process or whatever, so I add an &
at the end, like this: php worker.php >>/home/xxx/log 2>&1 &
But now the script is never executed, because nothing is appended to /home/xxx/log
and when I check ps -fux
the script is still there.
One thing I don't understand is that when I run that last command I get this:
xxx@xxx:/path$ php worker.php >>/home/xxx/log 2>&1 &
[1] 10659
Later on when I try to logout of the shell it tells me this:
xxx@xxx:/path$ logout
There are stopped jobs.
[1]+ Stopped php worker.php >> /home/xxx/log 2>&1
What is going on here? All I want is to run a script in the background and append all output to a file.
Thanks!
EDIT:
Here's an example.
user@box:~/nohuptest$ vim worker.php
user@box:~/nohuptest$ touch log
user@box:~/nohuptest$ php worker.php >> log 2>&1 &
[1] 31523
user@box:~/nohuptest$ cat log
[1]+ Stopped php worker.php >> log 2>&1
user@box:~/nohuptest$ php worker.php >> log 2>&1 &
[2] 31626
user@box:~/nohuptest$ cat log
[2]+ Stopped php worker.php >> log 2>&1
user@box:~/nohuptest$
user@box:~/nohuptest$ cat worker.php
<?php
echo "hello world\n";
?>
user@box:~/nohuptest$