svn: /phpdoc/en/trunk/features/ commandline.xml
| From: | Christopher Jones | Date: | Wed, 06 Jul 2011 19:55:49 +0000 |
| Subject: | svn: /phpdoc/en/trunk/features/ commandline.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-8440@lists.php.net to get a copy of this message | ||
sixd Wed, 06 Jul 2011 19:55:49 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=313025
Log:
Basic updates to CLI web server description based on the RFC
Changed paths:
U phpdoc/en/trunk/features/commandline.xml
Modified: phpdoc/en/trunk/features/commandline.xml
===================================================================
--- phpdoc/en/trunk/features/commandline.xml 2011-07-06 19:51:24 UTC (rev 313024)
+++ phpdoc/en/trunk/features/commandline.xml 2011-07-06 19:55:49 UTC (rev 313025)
@@ -1589,57 +1589,103 @@
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>