Basic updates to CLI web server description based on the RFC

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@313025 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Christopher Jones 2011-07-06 19:55:49 +00:00
parent afc1f13bdb
commit d03b529693

View file

@ -1589,57 +1589,103 @@ php >
be used in production.
</para>
<para>
URI requests are served from the current working directory where
PHP was started, unless the -t option is used to specify an
explicit document root.
</para>
<para>
If a URI request does not specify a file, then either index.html
or index.php in the given directory are returned. If neither file
exists, then a 404 response code is returned.
</para>
<para>
If a PHP file is given on the command line when the web server is
started it is treated as a "router" script for the web server.
The script is run at the start of each HTTP request. If this
script returns false, then the requested resource is returned
as-is. Otherwise the script's output is returned to the browser.
</para>
<example>
<title>Loading a file</title>
<title>Starting the web server</title>
<programlisting role="shell">
<![CDATA[
$ php -S localhost:8000 test.php
$ php -S localhost:8000
]]>
</programlisting>
&example.outputs;
<para>
The terminal will show:
</para>
<screen>
<![CDATA[
PHP Development Server is listening on localhost:8000 in . ... Press Ctrl-C to quit.
PHP Development Server is listening on localhost:8000 in /home/mydir ... Press Ctrl-C to quit.
]]>
</screen>
<para>
After URI requests for http://localhost:8000/ and
http://localhost:8000/myscript.html the terminal will show
something similar to:
</para>
<screen>
<![CDATA[
PHP Development Server is listening on localhost:8000 in /home/mydir ... Press Ctrl-C to quit.
[Fri Jul 1 06:29:04 2011] ::1:63530: /
[Fri Jul 1 06:29:10 2011] ::1:63532: /index.php
[Fri Jul 1 06:29:11 2011] ::1:63533: /myscript.html
]]>
</screen>
</example>
<example>
<title>Loading a directory</title>
<title>Starting with a specific document root directory</title>
<programlisting role="shell">
<![CDATA[
$ php -S localhost:8000 -t foo/
]]>
</programlisting>
&example.outputs;
<para>
The terminal will show:
</para>
<screen>
<![CDATA[
PHP Development Server is listening on localhost:8000 in foo/ ... Press Ctrl-C to quit.
PHP Development Server is listening on localhost:8000 in /home/mydir/foo ... Press Ctrl-C to quit.
]]>
</screen>
</example>
<example>
<title>Example output while making HTTP requests</title>
<title>Using a Router Script</title>
<para>
Requests for images will display them, but requests for HTML files will display "Welcome to PHP"
</para>
<programlisting role="php">
<![CDATA[
<?php
// hello.php
echo htmlspecialchars($_GET['hello'], ENT_QUOTES, 'UTF-8');
?>
]]>
// router.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"]))
return false; // serve the requested resource as-is.
else {
echo "<p>Welcome to PHP</p>";
}
?>]]>
</programlisting>
<programlisting role="shell">
<![CDATA[
$ php -S localhost:8000 hello.php
$ php -S localhost:8000 router.php
]]>
</programlisting>
&example.outputs.similar;
<para>
After several URI requests the terminal will show something similar to:
</para>
<screen>
<![CDATA[
PHP Development Server is listening on localhost:8000 in /home/mydir ... Press Ctrl-C to quit.
[Fri Jul 1 06:29:04 2011] ::1:63530: /
[Fri Jul 1 06:29:10 2011] ::1:63532: /?hello=world
[Fri Jul 1 06:29:11 2011] ::1:63533: /?hello=you
[Fri Jul 1 06:29:10 2011] ::1:63532: /mylogo.jpg
[Fri Jul 1 06:29:11 2011] ::1:63533: /abc.html
]]>
</screen>
</example>