Skip to content

Instantly share code, notes, and snippets.

@pyrou
Created May 27, 2015
Embed
What would you like to do?
Run a php server if file launched from CLI (from PayPal-PHP-SDK)
<?php
if (PHP_SAPI == 'cli') {
// If the index.php is called using console, we would try to host
// the built in PHP Server
if (version_compare(phpversion(), '5.4.0', '>=') === true) {
//exec('php -S -t ' . __DIR__ . '/');
$cmd = "php -S localhost:5000 -t " . __DIR__;
$descriptors = array(
0 => array("pipe", "r"),
1 => STDOUT,
2 => STDERR,
);
$process = proc_open($cmd, $descriptors, $pipes);
if ($process === false) {
fprintf(STDERR,
"Unable to launch PHP's built-in web server.\n");
exit(2);
}
fclose($pipes[0]);
$exit = proc_close($process);
exit($exit);
} else {
echo "You must be running PHP version less than 5.4. You would have to manually host the website on your local web server.\n";
exit(2);
}
} ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment