PHP 中的 PHP 网络服务器?

发布于 2024-11-10 01:45:39 字数 82 浏览 1 评论 0原文

即用 PHP 应用程序替换 Apache,当发送 .php 文件的 http 请求时,该应用程序会发回 html 文件?

这有多实用?

i.e to replace Apache with a PHP application that sent back html files when http requests for .php files are sent?

How practical is this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仙女 2024-11-17 01:45:40

除了 Nanoweb 之外,还有一个标准的 PEAR 组件来构建带有内置 Web 服务器的独立应用程序:
http://pear.php.net/package/HTTP_Server

同样,即将发布的 PHP 5.4 版本很可能包括一个内部迷你网络服务器,有助于简单的文件服务。 https://wiki.php.net/rfc/builtinwebserver

php -S localhost:8000

Apart from Nanoweb, there is also a standard PEAR component to build standalone applications with a built-in webserver:
http://pear.php.net/package/HTTP_Server

Likewise the upcoming PHP 5.4 release is likely to include an internal mini webserver which facilitates simple file serving. https://wiki.php.net/rfc/builtinwebserver

php -S localhost:8000
强者自强 2024-11-17 01:45:40

仅供参考,PHP 5.4 刚刚发布,带有内置网络服务器。现在您可以使用非常简单的命令来运行本地服务器,例如 -

$ cd ~/public_html
$ php -S localhost:8000

您将看到这样的请求和响应 -

PHP 5.4.0 Development Server started at Thu Jul 21 10:43:28 2011
Listening on localhost:8000
Document root is /home/me/public_html
Press 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

Just FYI, PHP 5.4 just released with in-built webserver. Now you can run a local server with very simple commands like -

$ cd ~/public_html
$ php -S localhost:8000

And you'll see the requests and responses like this -

PHP 5.4.0 Development Server started at Thu Jul 21 10:43:28 2011
Listening on localhost:8000
Document root is /home/me/public_html
Press 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
來不及說愛妳 2024-11-17 01:45:39

它已经完成了,但如果你想知道它有多实用,那么我建议你安装并使用 Apache bench 进行测试以查看结果:

http://nanoweb.si.kz/

Edit, A benchmark from the site:

Server Software:        aEGiS_nanoweb/2.0.1-dev
Server Hostname:        si.kz
Server Port:            80

Document Path:          /six.gif
Document Length:        28352 bytes

Concurrency Level:      20
Time taken for tests:   3.123 seconds
Complete requests:      500
Failed requests:        0
Broken pipe errors:     0
Keep-Alive requests:    497
Total transferred:      14496686 bytes
HTML transferred:       14337322 bytes
Requests per second:    160.10 [#/sec] (mean)
Time per request:       124.92 [ms] (mean)
Time per request:       6.25 [ms] (mean, across all concurrent requests)
Transfer rate:          4641.91 [Kbytes/sec] received

Connnection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0     0    1.9      0    13
Processing:    18   100  276.4     40  2739
Waiting:        1    97  276.9     39  2739
Total:         18   100  277.8     40  2750

Percentage of the requests served within a certain time (ms)
  50%     40
  66%     49
  75%     59
  80%     69
  90%    146
  95%    245
  98%    449
  99%   1915
 100%   2750 (last request)

It's already been done but if you want to know how practical it is, then i suggest you install and test with Apache bench to see the results:

http://nanoweb.si.kz/

Edit, A benchmark from the site:

Server Software:        aEGiS_nanoweb/2.0.1-dev
Server Hostname:        si.kz
Server Port:            80

Document Path:          /six.gif
Document Length:        28352 bytes

Concurrency Level:      20
Time taken for tests:   3.123 seconds
Complete requests:      500
Failed requests:        0
Broken pipe errors:     0
Keep-Alive requests:    497
Total transferred:      14496686 bytes
HTML transferred:       14337322 bytes
Requests per second:    160.10 [#/sec] (mean)
Time per request:       124.92 [ms] (mean)
Time per request:       6.25 [ms] (mean, across all concurrent requests)
Transfer rate:          4641.91 [Kbytes/sec] received

Connnection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0     0    1.9      0    13
Processing:    18   100  276.4     40  2739
Waiting:        1    97  276.9     39  2739
Total:         18   100  277.8     40  2750

Percentage of the requests served within a certain time (ms)
  50%     40
  66%     49
  75%     59
  80%     69
  90%    146
  95%    245
  98%    449
  99%   1915
 100%   2750 (last request)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文