/tmp/php-dev-server.log 2>&1 & echo $!', WEBSERVICE_SERVER_HOST, WEBSERVICE_SERVER_PORT, WEBSERVICE_SERVER_DOCROOT ); // Execute the command and store the process ID $output = array(); exec($command, $output); $pid = (int) $output[0]; echo sprintf( '%s - Web server started on %s:%d with PID %d', date('r'), WEBSERVICE_SERVER_HOST, WEBSERVICE_SERVER_PORT, $pid ) . PHP_EOL; // Kill the web server when the process ends register_shutdown_function(function() use ($pid) { echo sprintf('%s - Killing process with ID %d', date('r'), $pid) . PHP_EOL; exec('kill ' . $pid); }); ?>