AppServerFramework(ASF)简介:
当前版本0.01试用版。
框架基于PHP-Swoole扩展开发,通过配置文件可以自定义各种应用协议,默认支持http协议。
框架本身是一个完整的tcp_server,不再需要apache,gix,fpm这些,框架已包含log处理,mysql访问封装。
框架用fast-route库来做httproute处理,直接映射到控制器上,使用者只要写具体的控制器方法就可以实现rest风格的API。
至于性能,可以很低调的说:相当高,具体可以参考swoole相关文档: https://www.swoole.com/
安装运行环境:liux2.6+、php5.5+、mysql5.5+、swoole1.7.20+下载:https://github.com/xtjsxtj/asf
tar zxvf asf.tar.gz cd asf php ./bi/asf.php test_http start 也可以直接进入具体server目录直接运行入口脚本文件: cd asf/apps/test_httpphp ./idex.php查看当前server进程状态:php asf/bi/asf.php test_http status查看所有server运行状态:php asf/bi/asf.php listhttp_server开发当protocol为http(不设置则默认为http),server运行为http_server,这种模式下默认不需要做任何额外的配置,系统会按默认的路由规则分发到具体的控制器中处理,开发者只需要写具体的控制器和方法就可以。
下面是http_server,test_http的开发流程:
server配置文件:apps/test_http/cofig/server_cof.php
<?phpclass Swoole_cof { public static $cofig=array( 'server_ame' => 'test_http', //server名称 'log_level' => NOTICE, //跟踪级别 'liste' => 9501, //liste监听端口 'log_file' => '/asf/apps/test_http/idex.log', //log文件 ); }worker配置文件:apps/test_http/cofig/worker_cof.php
<?phpclass Worker_cof{ public static $cofig=array( 'log_level' => DEBUG, 'mysql' => array( 'socket' => '/tmp/mysql.sock', 'host' => 'localhost', 'port' => 3306, 'user' => 'user', 'password' => 'password', 'database' => 'test', 'charset' => 'utf8', ),}唯一主入口脚本:apps/test_http/idex.php
<?php>defie('BASE_PATH', __DIR__);require_oce BASE_PATH.'/../../lib/autoload.php';$server = ew swoole();$server->start();控制器:apps/test_http/cotroller/idex_cotroller.php
<?phpclass idex_cotroller exteds base_cotroller { public fuctio idex() { log::pr_log(DEBUG, jso_ecode($this->cotet)); log::pr_log(DEBUG, jso_ecode($this->param)); retur 'ok'; }}cotroller基于父类base_cotroller实现,而base_cotroller必须基于lib/cotroller.php的cotroller实现。
在这种默认的配置下:访问https://localhost:9501/idex/idex路由将会执行上面idex_cotroller控制器中的idex方法,http调用返回的结果是:ok
=>=>
评论