okeanrst / fastcgi-zf2-adapter
用于Zend Framework 2的PHPFastCGI适配器
dev-master
2016-05-03 10:40 UTC
Requires
- php: >=5.5
- paragonie/random_compat: dev-master
- phpfastcgi/fastcgi-daemon: dev-master
- zendframework/zendframework: ~2.4
This package is not auto-updated.
Last update: 2024-09-20 19:24:56 UTC
README
实验性!!!首先,应用程序的性能提高了10倍。随着请求数量的累积,应用程序占用的RAM量增加,响应时间也随之增加。测试了包含和不包含模块"zf-commons/zfc-user-doctrine-orm"的情况。
用法
以下是基于Zend Framework 2的FastCGI应用程序的示例。
安装ZendSkeletonApplication。将"PHPFastCGI Zend Framework 2 适配器"添加到您的应用程序中
php composer.phar require okeanrst/fastcgi-zf2-adapter
将以下文件添加到项目目录中
<?php // fcgi.php chdir(__DIR__); // Setup autoloading require_once 'vendor/autoload.php'; use PHPFastCGI\FastCGIDaemon\ApplicationFactory; use Okeanrst\FastCGIZF2Adapter\AppWrapper; define('DEV_MOVE', true); if (DEV_MOVE) { error_reporting(E_ALL & ~E_USER_DEPRECATED); ini_set("display_errors", 1); } // Create the kernel for the FastCGIDaemon library $kernel = new AppWrapper(require 'config/application.config.php'); // Create the symfony console application $consoleApplication = (new ApplicationFactory)->createApplication($kernel); // Run the symfony console application $consoleApplication->run();
Supervisor配置
要配置supervisor,打开您的/path/to/supervisor.d/,创建,例如,program_fastcgi_ZF2_1.conf,并添加以下内容
[program:fastcgi_zf2_1]
command=php /var/www/FastCGIDaemonZF2/fcgi.php run --port=5001 --host=localhost
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/fastcgi_zf2_1.err.log
stdout_logfile=/var/log/supervisor/fastcgi_zf2_1.out.log
运行supervisorctl,执行:reread然后reload。
Nginx配置
要配置nginx,打开您的/path/to/nginx/nginx.conf,并在不存在的情况下,在http块中添加以下include指令
http {
# ...
include sites-enabled/*.conf;
}
在/path/to/nginx/sites-enabled/zf2-app.localhost.conf下为您的项目创建一个虚拟主机配置文件,它应该看起来像下面这样
upstream workers {
server localhost:5001;
#server localhost:5002;
}
server {
listen 80;
server_name fastcgi_zf2;
root /var/www/FastCGIDaemonZF2/public;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass workers;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
error_log /var/log/nginx/fastcgi_zf2_error.log;
access_log /var/log/nginx/fastcgi_zf2_access.log;
}
重启nginx,现在您应该可以开始了!