php built in server,PHP built-in web server

Built-in web server

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"

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.net

Source: http://php.net/manual/en/features.commandline.webserver.php

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值