
一、Asf 是什么?
全称 API Services Framework, 用 C 语言编写的轻量级 PHP 扩展框架, 专注于 API 开发。
二、解决了什么问题?
- 把复杂的逻辑简单化(降低错误率, 减少代码量)
- 提升项目开发效率(您是否经历过,老板上午提需求,下午就得对外发布)
- 规范不合理的开发方式
- 解决输入输出的安全性问题
- 解决框架带来的性能消耗
三、有哪些优点呢?
- 与原生 PHP 做比较,只有少量的性能消耗
- 框架对常用类进行了实用的封装, 类随 PHP 进程启动就常驻内存
- 支持本地类库自动加载规则
- 支持多种配置文件格式(INI, PHP, PHP Array)
- 支持多种路由协议, 默认使用 RESTful 路由模式, 提供方便的路由配置器
- 提供实用的机制: GPC, Loader, Constants, Config, SG, 999, Utili
- 提供日志记录功能, 包括 PHP 错误日志, SQL CURD 日志
- 提供 DB 辅助函数(MySQL, Sqlite, Pgsql), 人性化 Query Builder
- 支持 Log buffer cache, Log resources are automatically cleared
- 遵循 PHP PSR Standards, PHP Coding Standards
- 框架结构简单, PHP 标准的扩展安装方式, 框架上手快。框架执行速度快, 更少的内存、CPU 使用
四、流程图

五、性能

5.1 总结
5.1.1 压测结论
没有挑取漂亮的数据, 或者配置一个为了压测的最优环境. 只是简单地采用以大部分 web 机器使用的环境进行测评。
这里只是给出了一种测试方法, 通过多次不同并发数测试结果得知, Asf 与原生 PHP 性能消耗是 6% ~ 15%。
5.1.2 业务开发速度结论
采用 Asf 框架开发业务, 代码量能节约 20% ~ 25%。
假如项目开发需要 4 天 x 8 小时, 能节约出整整 1 天 x 8 小时的工作时间。
六、安装
6.1 环境要求
PHP 7.0 + GCC 4.4.0+ (Recommended GCC 4.8+) 6.2 下载
git clone https://github.com/yulonghu/asf.git 6.3 在 Linux/Unix/Mac 下编译
$ /path/to/phpize $ ./configure --with-php-cOnfig=/path/to/php-config $ make && make install 6.4 文档
http://www.box3.cn/phpasf/index.html 七、开始使用
7.1 使用内置工具生成空项目
/php-bin-path/php /tools/asf_project.php /to-path/project_name 7.1.1 目录结构
+ public | - index.php + config | - config.php + library + modules | - Bootstrap.php | - Constants.php + api |+ services |- Index.php // Default service |+ logics |+ daos 7.1.2 config/config.php
<?php $cOnfigs= array( 'asf' => array( 'root_path' => realpath(dirname(__FILE__)), ) ); return $configs; 7.1.3 public/index.php
<?php define('APP_PATH', dirname(__DIR__)); $app = new Asf_Application(APP_PATH . '/config/config.php'); $app->run(); 7.1.4 Default service
<?php class IndexService { public function indexAction() { return 'Hello World'; } } 八、在 Nginx/Apache/Lighttpd 中运行
http://www.your-domain.com 8.1 输出结果
{ "errno": 0, "data": "Hello World" } 九、License
Asf is open source software under the PHP License v3.01
