App Server Framework (PHP Swoole)

码农软件 · 软件分类 · 高性能网络开发库 · 2019-08-31 23:14:03

软件介绍

App Server Framework (ASF)简介:

  • 当前版本0.01试用版。

  • 框架基于PHP-Swoole扩展开发,通过配置文件可以自定义各种应用协议,默认支持http协议。

  • 框架本身是一个完整的tcp_server,不再需要apache,nginx,fpm这些,框架已包含log处理,mysql访问封装。

  • 框架用fast-route库来做http route处理,直接映射到控制器上,使用者只要写具体的控制器方法就可以实现rest风格的API。

  • 至于性能,可以很低调的说:相当高,具体可以参考swoole相关文档: http://www.swoole.com/

安装运行

环境:linux2.6+、php5.5+、mysql5.5+、swoole1.7.20+
下载:https://github.com/xtjsxtj/asf

tar zxvf asf.tar.gz  
cd asf  
php ./bin/asf.php test_http start  

也可以直接进入具体server目录直接运行入口脚本文件:  
cd asf/apps/test_http
php ./index.php

查看当前server进程状态:
php asf/bin/asf.php test_http status

查看所有server运行状态:
php asf/bin/asf.php list

http_server开发

当protocol为http(不设置则默认为http),server运行为http_server,这种模式下默认不需要做任何额外的配置,系统会按默认的路由规则分发到具体的控制器中处理,开发者只需要写具体的控制器和方法就可以。

下面是http_server,test_http的开发流程:

  • server配置文件:apps/test_http/config/server_conf.php

<?php

class Swoole_conf {
    public static $config=array(
        'server_name' => 'test_http',  //server名称    
        'log_level' => NOTICE,         //跟踪级别
        'listen' => 9501,              //listen监听端口
        'log_file' => '/asf/apps/test_http/index.log',  //log文件
    );   
}
  • worker配置文件:apps/test_http/config/worker_conf.php

<?php

class Worker_conf{
    public static $config=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/index.php

<?php>
define('BASE_PATH', __DIR__);
require_once BASE_PATH.'/../../lib/autoload.php';

$server = new swoole();
$server->start();
  • 控制器:apps/test_http/controller/index_controller.php

<?php

class index_controller extends base_controller {       
    public function index() {
        log::prn_log(DEBUG, json_encode($this->content));
        log::prn_log(DEBUG, json_encode($this->param));         

        return 'ok';
    }
}
  • controller基于父类base_controller实现,而base_controller必须基于lib/controller.php的controller实现。

  • 在这种默认的配置下:访问 http://localhost:9501/index/index 路由将会执行上面index_controller控制器中的index方法,http调用返回的结果是:ok

本文地址:https://www.codercto.com/soft/d/13609.html

重新定义公司

重新定义公司

[美]埃里克·施密特 / 靳婷婷、陈序、何晔 / 中信出版社 / 2015-8 / 49.00

谷歌高管手绘风漫画视频: http://v.youku.com/v_show/id_XMTMxMzQ3NjMyMA==.html?from=y1.7-1.2 Google掌门人第一本国内引进作品 首次公开谷歌内部的管理与运营方法 全面解密执掌谷歌10余年的内幕故事 谷歌 创始人拉里•佩奇作序推荐 今日的谷歌是全球最具标志性的企业,在各个领域都有创新突破,并向技术......一起来看看 《重新定义公司》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具