phpfastcgi / expressive-adapter
Zend Expressive 框架的 PHPFastCGI 适配器
Requires
- php: >=5.5.0
- phpfastcgi/fastcgi-daemon: ^0.7
- zendframework/zend-expressive: ~0.1 | ^1.0
Requires (Dev)
- satooshi/php-coveralls: dev-master
- zendframework/zend-expressive-fastroute: ^1.0
- zendframework/zend-servicemanager: ^2.5
This package is auto-updated.
Last update: 2024-09-19 13:53:07 UTC
README
这是一个 PHP 包,允许 Zend Expressive 应用程序通过将其请求-响应结构暴露给 FastCGI 守护进程来减少开销。
访问项目网站。
简介
使用此包,Zend Expressive 应用程序可以在 FastCGI 启用的 Web 服务器保护下,在 HTTP 请求之间保持活跃。
当前状态
该项目目前处于开发的早期阶段,不被视为稳定。重要的是,这个库目前不支持上传文件。
欢迎贡献和建议。
安装
composer require "phpfastcgi/expressive-adapter:^0.1"
用法
<?php // command.php // Include the composer autoloader require_once dirname(__FILE__) . '/../vendor/autoload.php'; use PHPFastCGI\FastCGIDaemon\ApplicationFactory; use PHPFastCGI\Adapter\Expressive\ApplicationWrapper; use Zend\Expressive\AppFactory; // Create your Expressive app $app = AppFactory::create(); $app->get('/', function ($request, $response, $next) { $response->getBody()->write('Hello, World!'); return $response; }); // Create the kernel for the FastCGIDaemon library (from the Expressive app) $kernel = new ApplicationWrapper($app); // Create the symfony console application $consoleApplication = (new ApplicationFactory)->createApplication($kernel); // Run the symfony console application $consoleApplication->run();
如果您希望配置您的 FastCGI 应用程序与 Apache Web 服务器一起工作,您可以使用 Apache FastCGI 模块来管理您的应用程序。
这可以通过创建一个启动您的应用程序的 FastCGI 脚本,并将 FastCgiServer 指令插入到您的虚拟主机配置中来实现。
#!/bin/bash
php /path/to/command.php run
FastCgiServer /path/to/web/root/script.fcgi
默认情况下,守护进程将在 FCGI_LISTENSOCK_FILENO 上监听,但它也可以配置为监听 TCP 地址。例如
php /path/to/command.php run --port=5000 --host=localhost
如果您使用的是 NGINX 等类型的 Web 服务器,您将需要使用进程管理器来监控和运行您的应用程序。
AstroSplash:一个示例
AstroSplash 网站目前正在使用此适配器。如果您正在寻找示例集成,您可能会发现 源代码存储库 有所帮助。
两个重要的文件
此 PHP 脚本使用 Zend Expressive 应用程序对象创建和运行一个 FastCGI 应用程序。
由于使用了 NGINX,因此选择了 supervisord 来管理 FastCGI 应用程序的实例。在 Apache 中不需要这样做,因为其 FastCGI 模块内集成了进程管理器。此配置文件提供了监视 FastCGI 应用程序实例的说明。
NGINX 配置
以下是针对 AstroSplash 对 NGINX 配置文件所做的更改示例
upstream workers {
server localhost:5000;
server localhost:5001;
server localhost:5002;
server localhost:5003;
}
server {
# ...
location # ... {
include /etc/nginx/fastcgi_params;
fastcgi_pass workers;
# ...
}
# ...
}