I've written a PHP CLI script that executes on a Continuous Integration environment. One of the things it does is it runs Protractor tests.
My plan was to get the built-in PHP 5.4's built-in web server to run in the background:
php -S localhost:9000 -t foo/ bar.php &
And then run protractor tests that will use localhost:9000
:
protractor ./test/protractor.config.js
However, PHP's built-in web server doesn't run as a background service. I can't seem to find anything that will allow me to do this with PHP.
Can this be done? If so, how? If this is absolutely impossible, I'm open to alternative solutions.
If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.
PHP Command Line Interface (CLI) Running built-in web server As from version 5.4, PHP comes with built-in server. It can be used to run application without need to install other http server like nginx or apache. Built-in server is designed only in controller environment for development and testing purposes.
The preferred way of running PHP files is within a web server like Apache, Nginx, or IIS—this allows you to run PHP scripts from your browser.
Step 1: The client requests the webpage on the browser. Step 2: The server (where PHP software is installed) then checks for the . php file associated with the request. Step 3: If found, it sends the file to the PHP interpreter (since PHP is an interpreted language), which checks for requested data into the database.
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 &
You could do it the same way you would run any application in the background.
nohup php -S localhost:9000 -t foo/ bar.php > phpd.log 2>&1 &
Here, nohup is used to prevent the locking of your terminal. You then need to redirect stdout (>
) and stderr (2>
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With