I have a simple php script

echo $i;

Which I run from the command line

php myfile.php &

I would expect I can do other things in the command line, even before the scripts ends.
I do get a prompt, but when I press the enter I get [1]+ Stopped php myfile.php

2 Answers 2


This is expected if your terminal has the tostop option enabled. When that is set, any background process that tries to output to the terminal receives the SIGTTOU signal, and that signal's default handler stops the process. (This is done so that output from background processes doesn't mess up your terminal.)

You can disable this feature by running stty -tostop, in the same terminal.

Your current situation:

$ stty tostop
$ php ./t.php &
[1] 6484
[1]+  Stopped                 php ./t.php
$ # no messing up of the terminal, process stopped
$ fg
php ./t.php

Disable that feature:

$ stty -tostop
$ php ./t.php &
[1] 6481
$ # 01an2d 3now 45 6it m7esses 8up 9my term!
  • did the stty -tostop (with and without sudo) still not workin, same message Jan 4, 2012 at 19:40
  • this needs to be in the same terminal you run php from, just as in the examples I posted.
    – Mat
    Jan 4, 2012 at 19:42
  • It is in the same terminal. It seems like an issue of Ubuntu. If I do the & from inside a php file it works fine. Jan 4, 2012 at 20:00
  • What do you mean by "do the & from inside the php file"?
    – Mat
    Jan 4, 2012 at 20:01
  • inside the php I do [backtik]php t.php>log &[backtik] This, in php, runs the command inside the backtiks at the shell level (Did I say it right?). If I do that, the script runs async i.e. I can use the command line and the t.php runs in the background and outputs into log Jan 5, 2012 at 1:17

There's probably a better solution, but for me, on Ubuntu, it works if you run it in the foreground and suspend it with Ctrl-Z, and then background it with bg:

$ php myfile.php 
[4]+  Stopped                 php myfile.php
$ bg
[4]+ php myfile.php &
$ 2#3 it4 mess5es up 6my 7term8in9al too!
[4]   Done                    php myfile.php

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .