blockhead
blockhead

Reputation: 9705

How to run PHP's build in server in the background

I upgraded to PHP 5.5, and I can't run the server in the background anymore.

ablock@desktop:~/site$ php -S localhost:3000 -t public/ &
[1] 9689
ablock@desktop:~/site$ 

[1]+  Stopped                 php -S localhost:3000 -t public/
ablock@desktop:~/site$

As you can see, the server stops right away.

Upvotes: 0

Views: 1137

Answers (1)

user555
user555

Reputation: 1554

When a process is set to run in the background (using the & operator) it can no longer write to the terminal. A SIGTTOU signal is generated and it's default action is to terminate the process since it no longer is able to write to stdout.

By redirecting stdout somewhere writable we can make sure that there will be no SIGTTOU signal and thous no termination of the process.

php -S localhost:3000 -t public/ 1>/dev/null &

1> means stdout, while 2> means stderr, used for errors. Both can be redirected to a file or a pseudo-devices using &>.

Upvotes: 3

Related Questions