Created
May 27, 2015 09:54
-
-
Save pyrou/166373a04b043fe3c145 to your computer and use it in GitHub Desktop.
Run a php server if file launched from CLI (from PayPal-PHP-SDK)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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