<?php include "php_cli_server.inc"; php_cli_server_start('chdir(__DIR__); echo "okey";'); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS)); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS));
<?php require __DIR__ . "/../../sapi/cli/tests/php_cli_server.inc"; $code = <<<'FL' if(!ini_get('enable_post_data_reading')){ if($_SERVER['REQUEST_METHOD']=='POST'){ exit(file_get_contents('php://input')); } }else{ exit('Please SET php.ini: enable_post_data_reading = Off'); } FL; $postdata = "PASS"; $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata)); $context = stream_context_create($opts); php_cli_server_start("exit(file_get_contents('php://input'));", false, "-d enable_post_data_reading=Off"); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS, false, $context)); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS, false, $context));
<?php $stub = "<?php header('Content-Type: text/plain;');\nPhar::mount('this.file', '" . __FILE__ . "');\necho 'OK\n';\n__HALT_COMPILER(); ?>"; $p = new Phar(__DIR__ . '/issue0149.phar.php', 0, 'this'); $p['index.php'] = ""; # A Phar must have at least one file, hence this dummy $p->setStub($stub); unset($p); include "php_cli_server.inc"; php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1'); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0149.phar.php'); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0149.phar.php'); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/issue0149.phar.php'); @unlink(__DIR__ . '/issue0149.phar.php');
$file2 = "{$dir2}/index.php"; $main = "{$dir}/main.php"; @mkdir($dir1); @mkdir($dir2); @file_put_contents($main, '<?php include(\'' . $link . '/index.php\');'); @file_put_contents($file1, "TEST 1\n"); @file_put_contents($file2, "TEST 2\n"); while (filemtime($file1) != filemtime($file2)) { touch($file1); touch($file2); } @unlink($link); @symlink($dir1, $link); include "php_cli_server.inc"; //php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.revalidate_path=1'); php_cli_server_start('-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.revalidate_path=1 -d opcache.file_update_protection=0 -d realpath_cache_size=0'); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/main.php'); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/main.php'); @unlink($link); @symlink($dir2, $link); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/main.php'); echo file_get_contents('http://' . PHP_CLI_SERVER_ADDRESS . '/main.php'); $dir = dirname(__FILE__); $dir1 = "{$dir}/test1"; $dir2 = "{$dir}/test2"; $link = "{$dir}/test"; $file1 = "{$dir1}/index.php"; $file2 = "{$dir2}/index.php"; $main = "{$dir}/main.php"; @unlink($main); @unlink($link);
<?php include "php_cli_server.inc"; php_cli_server_start('var_dump($_SERVER["PHP_SELF"], $_SERVER["SCRIPT_NAME"], $_SERVER["PATH_INFO"], $_SERVER["QUERY_STRING"]);', null); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET /foo/bar?foo=bar HTTP/1.1 Host: {$host} HEADER )) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp); $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET /index.php/foo/bar/?foo=bar HTTP/1.0 Host: {$host}
<?php include "php_cli_server.inc"; php_cli_server_start(<<<'PHP' var_dump($_SERVER['SCRIPT_FILENAME']); PHP ); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER POST / HTTP/1.1 Host: {$host} HEADER )) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp);
<?php include dirname(__FILE__) . "/../../../../sapi/cli/tests/php_cli_server.inc"; php_cli_server_start(file_get_contents(dirname(__FILE__) . '/bug64433_srv.inc')); echo file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/index.php"); echo "default\n"; $codes = array(200, 201, 204, 301, 302, 303, 304, 305, 307, 404, 500); foreach ($codes as $code) { echo "{$code}: " . file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/index.php?status={$code}&loc=1"); } echo "follow=0\n"; $arr = array('http' => array('follow_location' => 0)); $context = stream_context_create($arr); foreach ($codes as $code) { echo "{$code}: " . file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/index.php?status={$code}&loc=1", false, $context); } echo "follow=1\n"; $arr = array('http' => array('follow_location' => 1)); $context = stream_context_create($arr); foreach ($codes as $code) { echo "{$code}: " . file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS . "/index.php?status={$code}&loc=1", false, $context); }
<?php include "php_cli_server.inc"; php_cli_server_start('var_dump($_SERVER["DOCUMENT_ROOT"], $_SERVER["SERVER_SOFTWARE"], $_SERVER["SERVER_NAME"], $_SERVER["SERVER_PORT"]);'); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS));
<?php include "php_cli_server.inc"; php_cli_server_start('var_dump($_SERVER["PATH_INFO"]);', null); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET /foo/bar HTTP/1.1 Host: {$host} HEADER )) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp); $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET /foo/bar/ HTTP/1.0 Host: {$host}
<?php include "php_cli_server.inc"; php_cli_server_start(<<<'PHP' if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) return false; // serve the requested resource as-is. else { echo "here"; } PHP ); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER POST /no-exists.jpg HTTP/1.1 Host: {$host} HEADER )) { while (!feof($fp)) { echo fgets($fp); break; } } fclose($fp);
<?php include "php_cli_server.inc"; php_cli_server_start(); var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS));
<?php include "php_cli_server.inc"; php_cli_server_start(<<<'PHP' echo "This should never echo"; PHP ); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } // Send a request with a fictitious request method, // I like smurfs, the smurf everything. if (fwrite($fp, <<<HEADER SMURF / HTTP/1.1 Host: {$host} HEADER )) { while (!feof($fp)) { echo fgets($fp); // Only echo the first line from the response, // the rest is not interesting break; } } fclose($fp);
<?php include "php_cli_server.inc"; php_cli_server_start(NULL, NULL); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $output = ''; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER POST / HTTP/1.1 Host: {$host} Content-Type: application/x-www-form-urlencoded Content-Length: 3 a=b HEADER )) { while (!feof($fp)) { $output .= fgets($fp); } } echo preg_replace("/<style>(.*?)<\\/style>/s", "<style>AAA</style>", $output), "\n"; fclose($fp); $output = ''; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); }
<?php include "php_cli_server.inc"; php_cli_server_start('print_r($_REQUEST); $_REQUEST["foo"] = "bar"; return FALSE;'); $doc_root = __DIR__; file_put_contents($doc_root . '/request.php', '<?php print_r($_REQUEST); ?>'); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER POST /request.php HTTP/1.1 Host: {$host} Content-Type: application/x-www-form-urlencoded Content-Length: 3 a=b HEADER )) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp); @unlink($doc_root . '/request.php');
<?php include "php_cli_server.inc"; php_cli_server_start(<<<'PHP' header('Bar-Foo: Foo'); var_dump(getallheaders()); var_dump(apache_request_headers()); var_dump(apache_response_headers()); PHP ); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET / HTTP/1.1 Host: {$host} Foo-Bar: Bar HEADER )) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp);
<?php include "php_cli_server.inc"; php_cli_server_start('<?php ?>', null); /* * If a Mime Type is added in php_cli_server.c, add it to this array and update * the EXPECTF section accordingly */ $mimetypes = ['html', 'htm', 'svg', 'css', 'js', 'png', 'webm', 'ogv', 'ogg']; function test_mimetypes($mimetypes) { foreach ($mimetypes as $mimetype) { list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die('Connect failed'); } file_put_contents(__DIR__ . "/foo.{$mimetype}", ''); $header = <<<HEADER GET /foo.{$mimetype} HTTP/1.1 Host: {$host} HEADER; if (fwrite($fp, $header)) { while (!feof($fp)) { $text = fgets($fp); if (strncasecmp("Content-type:", $text, 13) == 0) { echo "foo.{$mimetype} => ", $text; }
include "php_cli_server.inc"; php_cli_server_start(<<<'SCRIPT' ini_set('display_errors', 0); switch($_SERVER["REQUEST_URI"]) { case "/parse": try { eval("this is a parse error"); } catch (ParseError $e) { } echo "OK\n"; break; case "/fatal": eval("foo();"); echo "OK\n"; break; case "/compile": eval("class foo { final private final function bar() {} }"); echo "OK\n"; break; case "/fatal2": foo(); echo "OK\n"; break; default: return false; } SCRIPT ); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80;
<?php include "php_cli_server.inc"; php_cli_server_start('header(\'WWW-Authenticate: Digest realm="foo",qop="auth",nonce="XXXXX",opaque="' . md5("foo") . '"\');'); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET / HTTP/1.1 Host: {$host} Authorization: Basic Zm9vOmJhcg== HEADER )) { while (!feof($fp)) { echo fgets($fp); } }
<?php include "php_cli_server.inc"; php_cli_server_start('header("HTTP/1.1 304 Not Modified")', null); $headers = get_headers('http://' . PHP_CLI_SERVER_ADDRESS); echo count(array_filter($headers, function ($value) { return stripos($value, 'Content-Type') === 0; }));
<?php include "php_cli_server.inc"; php_cli_server_start('var_dump(count($_SERVER));', 'not-index.php'); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, "GET www.example.com:80 HTTP/1.1\r\n\r\n")) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp);
<?php include "php_cli_server.inc"; php_cli_server_start('var_dump($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"]);'); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET / HTTP/1.1 Host: {$host} Authorization: Basic Zm9vOmJhcg== HEADER )) { while (!feof($fp)) { echo fgets($fp); } }
<?php include "php_cli_server.inc"; php_cli_server_start('echo done, "\\n";', null); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $output = ''; // note: select() on Windows (& some other platforms) has historical issues with // timeouts less than 1000 millis(0.5). it may be better to increase these // timeouts to 1000 millis(1.0) (fsockopen eventually calls select()). // see articles like: http://support.microsoft.com/kb/257821 $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER POST /index.php HTTP/1.1 Host: {$host} Content-Type: multipart/form-data; boundary=---------123456789 Content-Length: 70 ---------123456789 Content-Type: application/x-www-form-urlencoded a=b HEADER )) { while (!feof($fp)) { $output .= fgets($fp); } } fclose($fp);
<?php include "php_cli_server.inc"; php_cli_server_start('var_dump($_SERVER["SERVER_PROTOCOL"]);'); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET / HTTP/1.1 Host: {$host} HEADER )) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp); $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET / HTTP/1.0 Host: {$host}
<?php include "php_cli_server.inc"; php_cli_server_start('http_response_code(100);'); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET / HTTP/1.1 Host: {$host} HEADER )) { while (!feof($fp)) { echo fgets($fp); } }
<?php include "php_cli_server.inc"; php_cli_server_start(<<<'PHP' header(' '); PHP ); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET / HTTP/1.1 Host: {$host} HEADER )) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp);
<?php include "php_cli_server.inc"; php_cli_server_start('var_dump($_SERVER["REQUEST_METHOD"]);'); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER SEARCH / HTTP/1.1 Host: {$host} HEADER )) { while (!feof($fp)) { echo fgets($fp); } }
<?php include "php_cli_server.inc"; php_cli_server_start('var_dump($_FILES);'); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } $post_data = <<<POST -----------------------------114782935826962 Content-Disposition: form-data; name="userfile"; filename="laruence.txt" Content-Type: text/plain I am not sure about this. -----------------------------114782935826962-- POST; $post_len = strlen($post_data); if (fwrite($fp, <<<HEADER POST / HTTP/1.1 Host: {$host} Content-Type: multipart/form-data; boundary=---------------------------114782935826962 Content-Length: {$post_len} {$post_data} HEADER
<?php include "php_cli_server.inc"; foreach ([308, 426] as $code) { php_cli_server_start(<<<PHP http_response_code({$code}); PHP ); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET / HTTP/1.1 HEADER )) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp); }
<?php include "php_cli_server.inc"; php_cli_server_start(<<<'PHP' var_dump($_COOKIE, $_SERVER['HTTP_FOO']); PHP ); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER GET / HTTP/1.1 cookie: foo=bar foo: bar HEADER )) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp);
<?php include "php_cli_server.inc"; php_cli_server_start(<<<'PHP' var_dump($_SERVER['REQUEST_METHOD']); PHP ); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port) ?: 80; $fp = fsockopen($host, $port, $errno, $errstr, 0.5); if (!$fp) { die("connect failed"); } if (fwrite($fp, <<<HEADER PATCH / HTTP/1.1 Host: {$host} HEADER )) { while (!feof($fp)) { echo fgets($fp); } } fclose($fp);