-
Notifications
You must be signed in to change notification settings - Fork 1
相关介绍
zmisgod edited this page Feb 25, 2018
·
1 revision
操作 | 介绍 |
---|---|
php index.php start | 启动 |
php index.php stop | 关闭 |
php index.php reload | 重启 |
php index.php status | 查看服务器状态 |
php index.php --help | 显示帮助命令 |
如果想要使用多端口监听tcp
、udp
,需要在配置文件中将multi_port
设置为true
,并在tcp
或者udp
的open
选项中设置为true
开启。
server | port | open |
---|---|---|
http | 9519 | true |
tcp | 9520 | true |
udp | 9521 | true |
路由 | 对应文件 | 方法名 |
---|---|---|
http://127.0.0.1:9519/index/benchmark |
App\Controller\Http\IndexController.php |
benchmark() |
其中,并且类文件的方法需要为公开的方法(public function)并且类需要继承App\Http\Controller
支持HTML模版,需要将控制器继承Core\Framework\ViewController
,然后在App
目录下新建View
因为本框架现仅支持2级路由,所以View
的下一级目录则为控制器的小写名称,然后此目录下则为某方法对应的view视图
路由 | 对应视图文件 |
---|---|
http://127.0.0.1:9519/demo/template |
App\Http\View\demo\template.php |
如果对应的视图找不到则会显示404页面,404页面默认在Public
目录下
内置mysqli,并实现相应的断线重连。使用方法:
use Core\Uti\DB\Mysqli;
Mysqli::getInstance()->query('show tables')->fetchall();
# debug
Mysqli::getInstance()->setDebug(true)->query('show tables')->printDebug();
详情见App\Controller\DemoController
这个类,demo包括下列方法的使用
- swoole_task
- swoole_timer_tick
- swoole_timer_clear
- swoole_timer_after
- tcp_client
- udp_client
- mysqli
- get/post参数接收
配置文件在Config文件夹中。获取配置文件示例:
$serverConfig = Config::getInstance()->getConfig('config.server');
其中,config为Config下的config.php文件
为了线上配置与开发配置便于管理,防止开发的配置文件用于生产环境,您可以在根目录创建一个.env
文件,在其中写相应的配置,然后再在Config\config.php
中使用Core\Uti\Tools\Tools::getInstance()->getEnv('KEY')
获取KEY
的配置(请看.env_sample
示例)。
支持EasyWechat
静态文件在Public目录下(暂时需要配合nginx处理静态资源)
server {
listen 80;
server_name your.server.name;
root to/your/path/TinySwoole/Public/;
if ( $uri = "/" ) {
rewrite ^(.*)$ /index last;
}
location / {
proxy_http_version 1.1;
proxy_set_header Connection "keep-alive";
proxy_set_header X-Real-IP $remote_addr;
# 判断文件是否存在,如果不存在,代理给Swoole
if (!-e $request_filename){
proxy_pass http://127.0.0.1:9519;
}
}
}