Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


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 "" & 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.

share|improve this question

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 &

share|improve this answer
Hmmm... even with the > /dev/null & it still goes into the jobs queue as stopped. – profitphp Oct 25 '11 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. – David Schwartz Oct 25 '11 at 18:16
thanks for the tip, I'll try that – profitphp Oct 26 '11 at 1:32

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.

share|improve this answer
ya, it's not that it wont run, it runs fine, i just cant background it with & – profitphp Oct 24 '11 at 21:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.