1

Ok, this seems really weird. When I am running a php script from the command line with & at the end to run it in the background, it's immediately stopped. I tried it on another server and it worked as expected; the job is running in the background.

The PHP

#!/usr/bin/php <?php sleep (5); 

Output on Server 1

[mk@li89-44 html]# ./test.php & [1] 4938 [mk@li89-44 html]# jobs [1]+ Running ./test.php & 

Output on Server 2

[mk@dev html]# ./test.php & [1] 4938 [mk@dev html]# jobs [1]+ Stopped ./test.php & 

On Server 2, I can get it in the background like so:

[mk@dev html]$ ./test.php ctrl + z [1]+ Stopped ./test.php [mk@dev html]$ bg [1]+ ./test.php & [mk@dev html]$ jobs [1]+ Running ./test.php 

Also on Server 2, if i do something like wget "http://fileserver.com/largefile.gz" & it goes into the bg running as expected. Running nohup ./test.php & on server 2 also works as expected.

Both servers are running centos, different versions, and different versions of php as well. I dunno if that's relevant, or if this can be explained just by the way jobs, fg, bg work on linux.

2 Answers 2

1

If you look at an strace of the process, you can see that PHP always initializes the terminal, which requires waiting for PHP to control the terminal:

ioctl(0, TCSETSW, {B38400 opost isig icanon echo ...}) = ? ERESTARTSYS --- {si_signo=SIGTTOU, si_code=SI_KERNEL} (Stopped (tty output)) --- --- Stopped (tty output) by SIGTTOU --- 

A simple workaround:

./test.php > /dev/null &

2
  • Hmmm... even with the > /dev/null & it still goes into the jobs queue as stopped. Commented Oct 25, 2011 at 16:00
  • Then you may need to strace it yourself and see what it's doing. If it's accessing standard input, for example, you may need a < /dev/null. Commented Oct 25, 2011 at 18:16
0

are you sure you have installed php-cli package?

check to if /usr/bin/php is a path of the binary, different distributions use different paths.

1
  • ya, it's not that it wont run, it runs fine, i just cant background it with & Commented Oct 24, 2011 at 21:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.