phpfastcgi / silex-adapter
一个用于将PHPFastCGI与Silex微框架集成的适配器
v0.5.0
2015-11-02 19:51 UTC
Requires
- php: >=5.5.0
- phpfastcgi/fastcgi-daemon: ^0.7
- silex/silex: ~1.0
Requires (Dev)
- satooshi/php-coveralls: dev-master
README
一个PHP包,允许Silex应用程序通过将其请求-响应结构暴露给FastCGI守护进程来减少开销。
访问项目网站。
简介
使用此适配器,Silex应用程序可以在HTTP请求之间保持存活,同时在启用FastCGI的Web服务器保护下运行。
当前状态
该项目目前处于开发初期,不稳定。重要的是,此库目前不支持上传文件。
欢迎贡献和建议。
安装
composer require "phpfastcgi/silex-adapter:^0.5"
用法
<?php // web/command.php // Include the composer autoloader require_once dirname(__FILE__) . '/../vendor/autoload.php'; use PHPFastCGI\FastCGIDaemon\ApplicationFactory; use PHPFastCGI\Adapter\Silex\ApplicationWrapper; use Silex\Application; // Create your Silex application $app = new Application; $app->get('/hello/{name}', function ($name) use ($app) { return 'Hello ' . $app->escape($name); }); // Create the kernel for the FastCGIDaemon library (from the Silex application) $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/silex/web/command.php run
FastCgiServer /path/to/silex/web/script.fcgi
默认情况下,守护进程将在FCGI_LISTENSOCK_FILENO上监听,但它也可以配置为监听TCP地址。例如
php /path/to/command.php run --port=5000 --host=localhost
如果您使用的是Nginx等Web服务器,您将需要使用进程管理器来监控和运行您的应用程序。