php 鸟哥 配置文件,鸟哥出品的高性能php框架YAF的安装和配置

本文介绍了Yaf框架的安装步骤及配置方法,包括下载、编译安装过程,并提供了nginx和Apache的配置示例。此外,还展示了Yaf应用程序的基本结构和初始化模板。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Yaf(Yet Another Freamwork)框架是中国国内教父级php程序员鸟哥的主力作品之一, 在php.net有鸟哥(惠新宸)的大名, 可谓国之骄傲。Yaf的运行并非堆积php类文件或者写一些其他php层面上的封装,而是采取了php扩展模式,随php常驻内存。想要学习Yaf, 需要先在环境上入手, 安装(编译)必要的扩展文件。

安装下载Yaf

先在Yaf的github页面右上角找到.zip文件包地址 或者到PHP官网上面的yaf扩展下载页面里下载。

然后将地址复制到控制台里用wget命令拿到

以下是.zip包的编译安装案例:wget https://github.com/laruence/yaf/archive/master.zip

unzip master.zip

cd yaf-master

设$PHP_BIN为php的bin目录,自己找一下这个目录放哪里啦$PHP_BIN/phpize

./configure --with-php-config=$PHP_BIN/php-config

make

make install

.tgz包的编译安装案例:

从php官网下载到.tgz的包放在~目录下tar -zxvf yaf-2.3.5.tgz

cd yaf-2.3.5

# 假设/phpstudy/server/php/bin为php的bin目录

/phpstudy/server/php/bin/phpize

./configure --with-php-config=/phpstudy/server/php/bin/php-config

make

make install

在php.ini里面填上yaf.so加载Yaf扩展extension=yaf.so

启用命名空间的方法也是在php.ini当中加两行yaf.use_namespace=1

yaf.environ="product"

其中environ这个配置项和application.ini的配置标准相关,product这个名字也是自己根据情况起的名字。

Yaf的配置

nginx的配置server {

listen       80;

server_name  maxtv5.wkwkk.com;

root   "/home/web/www.wkwkk.com/public";

if (!-e $request_filename) {

rewrite ^/(.*) /index.php/$1 last;

}

location / {

index  index.html index.htm index.php;

#autoindex  on;

}

location ~ \.php(.*)$ {

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

fastcgi_param  PATH_INFO  $fastcgi_path_info;

fastcgi_param  PATH_TRANSLATED  $document_root;

include        fastcgi_params;

}

}

注意: 如果发现重写规则失败,找不到文件,安装的是nginx较高(1.5+)版本的服务器,则把 / 符号改为 ?,即:rewrite ^/(.*) /index.php?$1 last;

别忘了重启生效

Apache的配置

.htaccess正文里写入以下代码:RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule .* index.php

Yaf的代码初始化模板

很多同学不会或者懒得使用鸟哥的代码初始化工具, 那么可以粘贴以下代码来用

先建立三个目录:  application  conf  public

在application当中建立目录: controllers  library  models  modules  plugins  views

application/Bootstrap.php文件代码:<?php

/**

* @name Bootstrap

* @author root

* @desc 所有在Bootstrap类中, 以_init开头的方法, 都会被Yaf调用,

* @see http://www.php.net/manual/en/class.yaf-bootstrap-abstract.php

* 这些方法, 都接受一个参数:Yaf_Dispatcher $dispatcher

* 调用的次序, 和申明的次序相同

*/

class Bootstrap extends Yaf\Bootstrap_Abstract

{

public function _initConfig()

{

Yaf\Registry::set('config', Yaf\Application::app()->getConfig());

}

public function _initPlugin(Yaf\Dispatcher $dispatcher)

{

// 注册一个插件

// $objSamplePlugin = new SamplePlugin();

// $dispatcher->registerPlugin($objSamplePlugin);

}

public function _initRoute(Yaf\Dispatcher $dispatcher)

{

$dispatcher->getInstance()->getRouter()->addConfig(Yaf\Registry::get('config')->routes);

}

public function _initView(Yaf\Dispatcher $dispatcher)

{

// 在这里注册自己的view控制器,例如smarty,firekylin

// $dispatcher->getInstance()->disableView();

}

public function _initSession(Yaf\Dispatcher $dispatcher)

{

// 初始化Session

}

public function _initCommonFunction()

{

// $directory = Yaf\Application::app()->getConfig()->application->directory;

// Yaf\Loader::import($directory . '/Constant.php');

// Yaf\Loader::import($directory . '/Common.php');

}

}

application/controllers/Index.php的代码<?php

class IndexController extends Yaf\Controller_Abstract

{

public function indexAction()

{

// echo 'do something';

return false;

}

}

application/plugins/Sample.php的代码:<?php

/**

* @name SamplePlugin

* @desc Yaf定义了如下的6个Hook,插件之间的执行顺序是先进先Call

* @see http://www.php.net/manual/en/class.yaf-plugin-abstract.php

* @author root

*/

class SamplePlugin extends Yaf\Plugin_Abstract

{

public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)

{

}

public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)

{

}

public function dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)

{

}

public function preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)

{

}

public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)

{

}

public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)

{

}

}

conf/application.ini的代码[common]

application.directory=APP_PATH "/application/"

;application.dispatcher.catchException=TRUE

application.modules="Index"

[routes]

routes.article.type="regex"

routes.article.match="#^/article/([0-9]+).html$#"

routes.article.route.module="Index"

routes.article.route.controller="Index"

routes.article.route.action="Todo"

routes.article.map.1="id"

routes.simple.type = "simple"

routes.simple.module = "m"

routes.simple.controller = "c"

routes.simple.action = "a"

[product : common:routes]

[develop : common:routes]

public/index.php 也就是入口文件的代码:<?php

/**

* Yaf框架基本入口

* @author caster 20160806

*/

header('Content-type:text/html;charset=utf-8');

// 开发模式

ini_set('display_errors',1);

error_reporting(E_ALL);

date_default_timezone_set('PRC');

// 定义入口文件

define('APP_PATH', __DIR__ . '/../'); // 指向public上一级

define('ROOT_PATH',__DIR__);

$app = new Yaf\Application(APP_PATH . '/conf/application.ini');

$app->bootstrap()->run();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值