脚本宝典收集整理的这篇文章主要介绍了新一代轻量级PHP扩展框架 Asf,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
一、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 @H_964_126@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"
}
@H_389_360@九、License
Asf is open source Software under the PHP License v3.01
以上是脚本宝典为你收集整理的新一代轻量级PHP扩展框架 Asf全部内容,希望文章能够帮你解决新一代轻量级PHP扩展框架 Asf所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。