| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This library is free software; you can redistribute it and/or
|
|---|
| 6 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 7 | License as published by the Free Software Foundation; either
|
|---|
| 8 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This library is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | Lesser General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | License along with this library; if not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|---|
| 18 | MA 02110-1301 USA.
|
|---|
| 19 |
|
|---|
| 20 | Followed the guide at http://tech.vg.no/2013/07/19/using-phps-built-in-web-server-in-your-test-suites/
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | // Command that starts the built-in web server
|
|---|
| 24 | $command = sprintf(
|
|---|
| 25 | 'php -S %s:%d -t %s >/tmp/php-dev-server.log 2>&1 & echo $!',
|
|---|
| 26 | WEBSERVICE_SERVER_HOST,
|
|---|
| 27 | WEBSERVICE_SERVER_PORT,
|
|---|
| 28 | WEBSERVICE_SERVER_DOCROOT
|
|---|
| 29 | );
|
|---|
| 30 |
|
|---|
| 31 | // Execute the command and store the process ID
|
|---|
| 32 | $output = array();
|
|---|
| 33 | exec($command, $output);
|
|---|
| 34 | $pid = (int) $output[0];
|
|---|
| 35 |
|
|---|
| 36 | echo sprintf(
|
|---|
| 37 | '%s - Web server started on %s:%d with PID %d',
|
|---|
| 38 | date('r'),
|
|---|
| 39 | WEBSERVICE_SERVER_HOST,
|
|---|
| 40 | WEBSERVICE_SERVER_PORT,
|
|---|
| 41 | $pid
|
|---|
| 42 | ) . PHP_EOL;
|
|---|
| 43 |
|
|---|
| 44 | // Kill the web server when the process ends
|
|---|
| 45 | register_shutdown_function(function() use ($pid) {
|
|---|
| 46 | echo sprintf('%s - Killing process with ID %d', date('r'), $pid) . PHP_EOL;
|
|---|
| 47 | exec('kill ' . $pid);
|
|---|
| 48 | });
|
|---|
| 49 | ?>
|
|---|