rfc:builtinwebserver

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:builtinwebserver [2011/03/02 20:48] – Correct the date. moriyoshirfc:builtinwebserver [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Request for Comments: Built-in web server ====== ====== Request for Comments: Built-in web server ======
   * Version: 1.0   * Version: 1.0
-  * Date: 2011-03-03+  * Date: 2011-06-020
   * Author: Moriyoshi Koizumi <moriyoshi.at.php.net>   * Author: Moriyoshi Koizumi <moriyoshi.at.php.net>
-  * Status: Draft+  * Status: Implemented in 5.4
   * First Published at: http://wiki.php.net/rfc/builtinwebserver   * First Published at: http://wiki.php.net/rfc/builtinwebserver
   * Other formats ..   * Other formats ..
Line 9: Line 9:
 ===== Introduction ===== ===== Introduction =====
  
-When it comes to web development, most people wouldn't doubt PHP's best friend is Apache HTTPD Server.  Having that said, developers who experienced any of web application frameworks of other scripting languages such as Ruby on Rails and Django may well find it cumbersome to set up httpd.conf just to use it within a development environment as those are most likely accompanied by a tiny web server that can be launched with a simple command line.+When it comes to web development, most people wouldn't doubt PHP's best friend is Apache HTTPD Server.  Having said that, developers who experienced any of web application frameworks of other scripting languages such as Ruby on Rails and Django may well find it cumbersome to set up httpd.conf just to use it within a development environment as those are most likely accompanied by a tiny web server that can be launched with a simple command line.
  
-While PHP is capable enough to write a standalone web server in thanks to the enhanced stream APIs, writing a web server in PHP for each web application framework should not really make sense because it could not be made compatible enough with the standard environment because it is difficult to emulate per-request resource handling in the main event loop.+While PHP is capable enough to write a standalone web server inthanks to the enhanced stream APIs, writing it in PHP for each web application framework should not really make sense because it could not be made compatible enough with the standard environment due to difficulty of emulating PHP'per-request resource handling in the main event loop without Runkit.
  
 Therefore, it is natural that CLI version of PHP has a feature that the binary itself can be a web server. Therefore, it is natural that CLI version of PHP has a feature that the binary itself can be a web server.
  
 ===== Proposal ===== ===== Proposal =====
-CLI version of PHP will have a new command-line option -S followed by a host address  (either in numeric or alphabetic) and a port number delimited by a colon, which will launch a builtin web server listening on the given address and port.   +CLI version of PHP will have a new command-line option -S followed by a host address  (either in numeric or alphabetic) and a port number delimited by a colon, which will launch a builtin web server listening on the given address and port, 
-<code> + 
-php -S localhost:8000 +  php -S localhost:8000 
-</code>+ 
 +with the following output: 
 + 
 +  Server is listening on localhost:8000... Press CTRL-C to quit. 
 + 
 +Every request will be shown in the console as well. 
 + 
 +  Server is listening on localhost:8000... Press CTRL-C to quit. 
 +  [Thu Mar  3 05:42:06 2011] ::1:56258: / 
 +  [Thu Mar  3 05:42:06 2011] ::1:56259: /?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 
 +  [Thu Mar  3 05:42:06 2011] ::1:56260: /?=PHPE9568F35-D428-11d2-A769-00AA001ACF42
  
 ==== Specifying Document Root ==== ==== Specifying Document Root ====
-The document root can be specified through a remaining argument that does not belong to any option that starts with a hyphen.  If omitted, the current working directory will be used.+The document root can be specified through the -t option.  If omitted, the current working directory will be used.
  
-<code> +  php -S localhost:8000 -t docroot 
-php -S localhost:8000 docroot + 
-</code>+==== Directory Indexes ==== 
 + 
 +If a request is made for a directory, the web server will return index.html or index.php if they exist in the directory.
  
 ==== Router Script ==== ==== Router Script ====
 Quite a few number of web applications rely on the URL rewrite feature of the web server to do the custom routing on pretty paths.  One can use a router script to emulate the feature.  A router script is a script which will be dispatched on every request to the web server and determine how to handle it.  If the script returns false, the request is then handled in the default manner.  Otherwise, it is supposed to give an appropriate response to the client. Quite a few number of web applications rely on the URL rewrite feature of the web server to do the custom routing on pretty paths.  One can use a router script to emulate the feature.  A router script is a script which will be dispatched on every request to the web server and determine how to handle it.  If the script returns false, the request is then handled in the default manner.  Otherwise, it is supposed to give an appropriate response to the client.
  
-<code> +  php -S localhost:8000 routing.php
-php -S localhost:8000 routing.php +
-</code>+
  
-If the path to a file is given in place of document root the file will be regarded as a router script and the document root will then be set to the directory where it belongs.+If the path to a file is given, the file will be regarded as a router script and the document root will then be set to the directory where it belongs.
  
 <code php> <code php>
Line 54: Line 64:
 ===== Changelog ===== ===== Changelog =====
 2011-03-03: initial version 2011-03-03: initial version
- 
- 
rfc/builtinwebserver.1299098935.txt.gz · Last modified: 2017/09/22 13:28 (external edit)