tabuna / stone
Laravel Stone - 使用 ReactPHP 的 HTTP 服务器
0.0.1
2018-10-17 21:23 UTC
Requires
- react/event-loop: ^1.0
- react/http: ^0.8.3
- symfony/psr-http-message-bridge: ^1.1
This package is auto-updated.
Last update: 2024-09-13 06:02:03 UTC
README
使用 ReactPHP,我们保持应用程序在请求之间的活跃状态,因此当服务器启动时,我们只执行一次这个引导:请求中不包含足迹。然而现在情况发生了变化:我们容易受到内存消耗、致命错误、状态性和代码更新担忧的影响。
安装
使用 Composer 的安装器
$ composer require tabuna/stone
示例
运行的最简单方式
$ php vendor/bin/stone
您也可以指定端口
$ php vendor/bin/stone -p 8000
它不会干扰您的应用程序,所以请放心
使生产就绪
Supervisord
安装 Supervisord
$ sudo apt-get install -y supervisor
以下是一个配置示例(在 /etc/supervisord/conf.d
中创建一个 *.conf
文件)
[program:laravel-stone-server] command=php /path/to/your/code/vendor/bin/stone -p 800%(process_num) process_name=%(program_name)s-%(process_num)d numprocs=4 umask=022 user=foobar stdout_logfile=/var/log/supervisord/%(program_name)s-%(process_num)d.log ; stdout log path, NONE for none; default AUTO stderr_logfile=/var/log/supervisord/%(program_name)s-%(process_num)d-error.log ; stderr log path, NONE for none; default AUTO autostart=true autorestart=true startretries=3
它将
- 在端口 8000、8001、8002 和 8003 上运行 4 个服务器
- 如果它们崩溃会自动重启它们(将尝试最多 3 次,然后放弃)
Nginx 作为负载均衡器
我们在这里做的是仅代理指向本地文件之外的请求。
upstream stone { server 127.0.0.1:8000; server 127.0.0.1:8001; server 127.0.0.1:8002; server 127.0.0.1:8003; } server { listen 80; server_name example.com; root /example.com/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.html index.htm index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } error_page 404 /index.php; location ~ \.php$ { proxy_pass http://stone; break; } location ~ /\.(?!well-known).* { deny all; } }
捐赠与支持
如果您想通过捐赠来支持开发,您可以通过这里进行捐赠。😊
许可协议
MIT 许可协议 (MIT)。请参阅许可文件以获取更多信息。