Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品与服务 | Email

第 9 章 Phalcon - High performance PHP framework

目录

9.1. 安装配置 Phalcon
9.1.1. Ubuntu
9.1.2. 编译安装
9.1.3. Nginx 配置
9.1.4. Phalcon Developer Tools
9.2. DevTools
9.2.1. 创建项目
9.2.2. 创建控制器
9.3. dispatcher
9.4. cache
9.4.1. Redis 缓存
9.4.2. 多种缓存混合使用

http://phalconphp.com/

与其他框架实现方法不同,Phalcon直接采用C代码编写,编译成PHP共享库载入。所以速度是最快的。

9.1. 安装配置 Phalcon

9.1.1. Ubuntu

sudo apt-add-repository ppa:phalcon/stable
sudo apt-get update
sudo apt-get install php5-phalcon
			

9.1.2. 编译安装

			
cd /usr/local/src/

git clone git://github.com/phalcon/cphalcon.git
cd cphalcon/build
./install

cat > /srv/php/etc/conf.d/phalcon.ini <<EOF
extension=phalcon.so
EOF
			
			

确认安装是否成功

# php -m | grep phalcon
phalcon
			

9.1.3. Nginx 配置

			
server {
    listen       80;
    server_name  localhost;

    charset utf-8;

    access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /www/phalcon/public;
        index  index.html index.php;
    		if ($request_filename !~ (js|css|img|/images|robots/.txt|index/.php) ) {
        		rewrite ^/(.*)$ /index.php?_url=/$1 last;
        		break;
    		}
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/local/www/nginx-dist;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ /index.php {
        root           /www/phalcon/public;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /www/phalcon/public$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}
			
			

注意两点:

一是rewrite设置需要 $request_filename 过滤文件与目录

二是fastcgi配置location ~ /index.php 这样的设置是为了".php"只能运行 index.php,其他目录下的.php文件无法运行,这样解决的注入与非法脚本运行。

9.1.4. Phalcon Developer Tools

# pear channel-discover pear.phalconphp.com
# pear install phalcon/Devtools
			

运行 phalcon 测试是否正确安装

# phalcon

Phalcon DevTools (2.0.7)

Help:
  Lists the commands availables in Phalcon devtools

Available commands:
  commands (alias of: list, enumerate)
  controller (alias of: create-controller)
  model (alias of: create-model)
  all-models (alias of: create-all-models)
  project (alias of: create-project)
  scaffold
  migration
  webtools
			
comments powered by Disqus