PHPbuilt-inwebserver
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHPbuilt-inwebserver,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3230字,纯文字阅读大概需要5分钟。
内容图文
![PHPbuilt-inwebserver](/upload/InfoBanner/zyjiaocheng/193/46372608db3648e19e328522f878f6c8.jpg)
As of PHP 5.4.0, the CLI SAPI provides a built-in web server.
This web server is designed for developmental purposes only, and should not be used in production.
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.
If a URI request does not specify a file, then either index.php or index.html in the given directory are returned. If neither file exists, then a 404 response code is returned.
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.
Example #1 Starting the web server
$ cd ~/public_html$ php -S localhost:8000
The terminal will show:
PHP 5.4.0 Development Server started at Thu Jul 21 10:43:28 2011Listening on localhost:8000Document root is /home/me/public_htmlPress Ctrl-C to quit
After URI requests for http://localhost:8000/ and http://localhost:8000/myscript.html the terminal will show something similar to:
PHP 5.4.0 Development Server started at Thu Jul 21 10:43:28 2011Listening on localhost:8000Document root is /home/me/public_htmlPress Ctrl-C to quit.[Thu Jul 21 10:48:48 2011] ::1:39144 GET /favicon.ico - Request read[Thu Jul 21 10:48:50 2011] ::1:39146 GET / - Request read[Thu Jul 21 10:48:50 2011] ::1:39147 GET /favicon.ico - Request read[Thu Jul 21 10:48:52 2011] ::1:39148 GET /myscript.html - Request read[Thu Jul 21 10:48:52 2011] ::1:39149 GET /favicon.ico - Request read
Example #2 Starting with a specific document root directory
$ cd ~/public_html$ php -S localhost:8000 -t foo/
The terminal will show:
PHP 5.4.0 Development Server started at Thu Jul 21 10:50:26 2011Listening on localhost:8000Document root is /home/me/public_html/fooPress Ctrl-C to quit
Example #3 Using a Router Script
Requests for images will display them, but requests for HTML files will display "Welcome to PHP"
// router.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"]))
return false; // serve the requested resource as-is.
else {
echo "
Welcome to PHP
";}
?>
$ php -S localhost:8000 router.php
After several URI requests the terminal will show something similar to:
PHP 5.4.0 Development Server started at Thu Jul 21 10:53:19 2011Listening on localhost:8000Document root is /home/me/public_htmlPress Ctrl-C to quit.[Thu Jul 21 10:53:45 2011] ::1:55801 GET /mylogo.jpg - Request read[Thu Jul 21 10:53:52 2011] ::1:55803 GET /abc.html - Request read[Thu Jul 21 10:53:52 2011] ::1:55804 GET /favicon.ico - Request read
Author: php.com
Source: http://php.com/manual/en/features.commandline.webserver.php
内容总结
以上是互联网集市为您收集整理的PHPbuilt-inwebserver全部内容,希望文章能够帮你解决PHPbuilt-inwebserver所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。