wordpress-psr / swoole
在基于 Swoole 的高性能 HTTP 服务器上运行的 WordPress。
dev-master
2022-04-04 04:42 UTC
Requires
- chubbyphp/chubbyphp-swoole-request-handler: ^1.1
- johnpbloch/wordpress-core-installer: ^2.0
- nyholm/psr7: ^1.4.0
- superdav42/wordpress-core: dev-master
- wordpress-psr/request-handler: dev-master
Requires (Dev)
- mezzio/mezzio-swoole: ^3.3
- roave/security-advisories: dev-master
- swoole/ide-helper: @dev
This package is auto-updated.
Last update: 2024-09-04 10:11:35 UTC
README
一种使用高性能、事件驱动的 Swoole HTTP 服务器运行 WordPress 的方法。该项目仍在开发中,可以预期存在许多错误。欢迎提交拉取请求。
安装
Swoole 必须从 pecl 或 其他来源 安装。
composer create-project -s dev wordpress-psr/swoole wordpress-swoole
启动 swoole 进程
cd wordpress-swoole
php server.php
访问 http://0.0.0.0:8889/ 应该会重定向到配置并执行 WordPress 的著名 5 分钟安装。如果由于任何原因失败,请手动创建 wp-config.php。
cp wordpress/wp-config-sample.php wp-config.php
然后使用 WP CLI 运行安装。
wp core install --url='http://0.0.0.0:8889' --title='Swoole Test' --admin_user=admin --admin_password=password --skip-email
概述
大部分工作由 WordPress PSR 请求处理器 完成。该项目主要是将请求处理器与 chubbyphp-swoole-request-handler 粘合在一起。基本流程如下
- 接收 Swoole 请求。
- 将 Swoole 请求转换为 PSR-7 请求。
- 传递给 WordPress 请求处理器。
- 接收 PSR-7 响应。
- 转换为 Swoole 响应。
由于 WordPress 使用 WP_ADMIN
等常量指定某些请求的来源,因此开发了系统以将某些请求路由到特定的工作者,以便管理员可以从前端使用单独的池提供服务。在这种情况下,流程如下
- 接收 Swoole 请求。
- 将 Swoole 请求转换为 PSR-7 请求。
- 确定请求是否为特殊路由。
- 使用 Swoole\Server::task() 将请求发送到指定用于特殊路由的任务工作者。
- 任务工作者将请求传递给 WordPress 请求处理器。
- 将 PSR-7 响应发送回主工作者。
- 转换为 Swoole 响应。
运行
php server.php
性能
大约 2 倍的性能提升。仅使用基本安装数据的首页 ab 测试显示,在 Swoole 上运行 WordPress 的请求为每秒 695 次,而使用 php-fpm 的请求为每秒 324 次。Nginx+php-fpm
ab -n 10000 -c 8 http://pm.localhost:8088/
Server Software: nginx/1.16.1
Server Hostname: pm.localhost
Server Port: 8088
Document Path: /
Document Length: 8570 bytes
Concurrency Level: 8
Time taken for tests: 30.841 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 88020000 bytes
HTML transferred: 85700000 bytes
Requests per second: 324.25 [#/sec] (mean)
Time per request: 24.672 [ms] (mean)
Time per request: 3.084 [ms] (mean, across all concurrent requests)
Transfer rate: 2787.14 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 12 25 3.6 25 38
Waiting: 12 24 3.6 25 38
Total: 12 25 3.6 25 38
Percentage of the requests served within a certain time (ms)
50% 25
66% 26
75% 27
80% 28
90% 29
95% 30
98% 32
99% 32
100% 38 (longest request)
Swoole
ab -n 10000 -c 8 http://0.0.0.0:8889/
Server Software: swoole-http-server
Server Hostname: 0.0.0.0
Server Port: 8889
Document Path: /
Document Length: 6256 bytes
Concurrency Level: 8
Time taken for tests: 14.383 seconds
Complete requests: 10000
Failed requests: 3996
(Connect: 0, Receive: 0, Length: 3996, Exceptions: 0)
Total transferred: 64911212 bytes
HTML transferred: 62561212 bytes
Requests per second: 695.28 [#/sec] (mean)
Time per request: 11.506 [ms] (mean)
Time per request: 1.438 [ms] (mean, across all concurrent requests)
Transfer rate: 4407.40 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 7 11 11.8 11 448
Waiting: 7 11 11.8 11 448
Total: 7 11 11.8 11 448
Percentage of the requests served within a certain time (ms)
50% 11
66% 11
75% 11
80% 12
90% 12
95% 12
98% 13
99% 15
100% 448 (longest request)
上述测试是在 PHP 7.4.15、swoole 4.6.4 和 i7-1065G7 CPU 上运行的。
许可证
GPL,请参阅 LICENSE。