Annotation of embedaddon/php/sapi/cli/tests/php_cli_server.inc, revision 1.1
1.1 ! misho 1: <?php
! 2: define ("PHP_CLI_SERVER_ADDRESS", "localhost:8964");
! 3:
! 4: function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE) {
! 5: $php_executable = getenv('TEST_PHP_EXECUTABLE');
! 6: $doc_root = __DIR__;
! 7: $router = "index.php";
! 8:
! 9: if ($code) {
! 10: file_put_contents($doc_root . '/' . $router, '<?php ' . $code . ' ?>');
! 11: }
! 12:
! 13: $descriptorspec = array(
! 14: 0 => STDIN,
! 15: 1 => STDOUT,
! 16: 2 => STDERR,
! 17: );
! 18:
! 19: if (substr(PHP_OS, 0, 3) == 'WIN') {
! 20: $cmd = "{$php_executable} -t {$doc_root} -n -S " . PHP_CLI_SERVER_ADDRESS;
! 21: if (!$no_router) {
! 22: $cmd .= " {$router}";
! 23: }
! 24:
! 25: $handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true, "suppress_errors" => true));
! 26: } else {
! 27: $cmd = "exec {$php_executable} -t {$doc_root} -n -S " . PHP_CLI_SERVER_ADDRESS;
! 28: if (!$no_router) {
! 29: $cmd .= " {$router}";
! 30: }
! 31: $cmd .= " 2>/dev/null";
! 32:
! 33: $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root);
! 34: }
! 35:
! 36: register_shutdown_function(
! 37: function($handle) use($router) {
! 38: proc_terminate($handle);
! 39: @unlink(__DIR__ . "/{$router}");
! 40: },
! 41: $handle
! 42: );
! 43: usleep(50000);
! 44: }
! 45: ?>
! 46:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>