How to run PHP embedded web server in the background?

I wrote a PHP CLI script that runs in a continuous integration environment. One of the things she does is run Protractor tests.

My plan was to get PHP 5.4's built - in embedded web server to run in the background:

php -S localhost:9000 -t foo/ bar.php & 

And then run the protractor tags that will use localhost:9000 :

 protractor ./test/protractor.config.js 

However, the PHP embedded web server does not start as a help service. I can not find anything that will allow me to do this using PHP.

Can this be done? If so, how? If this is absolutely impossible, I am open to alternative solutions.

+9
source share
3 answers

You can do this just like any application in the background.

 nohup php -S localhost:9000 -t foo/ bar.php > phpd.log 2>&1 & 

Here nohup is used to prevent your terminal blocking. Then you need to redirect stdout ( > ) and stderr ( 2> ).

+21
source

There is also a way to stop the launch of the embedded php server in the background :

 # Run in the background as Devon advised nohup php -S localhost:9000 -t foo/ bar.php > phpd.log 2>&1 & # Get last background process PID PHP_SERVER_PID=$! # rinning tests and everything... protractor ./test/protractor.config.js # Send SIGQUIT to php built-in server running in background to stop it kill -3 $PHP_SERVER_PID 

This is useful when you need to run tests at some stage of CI, etc.

+8
source

You can use &> to redirect both stderr and stdout to /dev/null (nowhere).

 nohup php -S 0.0.0.0:9000 -t foo/bar.php &> /dev/null & 
0
source

Source: https://habr.com/ru/post/987299/


All Articles