本文整理汇总了PHP中php_cli_server_start函数的典型用法代码示例。如果您正苦于以下问题:PHP php_cli_server_start函数的具体用法?PHP php_cli_server_start怎么用?PHP php_cli_server_start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了php_cli_server_start函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: php_cli_server_start
<?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));
示例2: exit
<?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));
示例3: header
<?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');
示例4: include
$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);
示例5: php_cli_server_start
<?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}
示例6: php_cli_server_start
<?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);
示例7: dirname
<?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);
}
示例8: php_cli_server_start
<?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));
示例9: php_cli_server_start
<?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}
示例10: php_cli_server_start
<?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);
示例11: php_cli_server_start
<?php
include "php_cli_server.inc";
php_cli_server_start();
var_dump(file_get_contents("http://" . PHP_CLI_SERVER_ADDRESS));
示例12: php_cli_server_start
<?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);
示例13: php_cli_server_start
<?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");
}
示例14: php_cli_server_start
<?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');
示例15: php_cli_server_start
<?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);