Github地址:https://github.com/jiangliuer326442/rubyPHP
RubyPHP是一个轻量级的PHP MVC框架,支持Swoole和CLI两种运行模式。
swoole是PHP的一个插件,点击以下链接安装,区别于普通PHP的地方在于:类的实例化不必等到每次请求的时候创建,mysql和redis使用长连接,不必每次请求的时候再去创建。在高并发的场景下可与java相媲美。
define("FRAMEWORK","/data/user/fanghailiang/swoole/RubyPHP/");
require(FRAMEWORK."index.php");
$config['route'] = array(
'default' => 'default/welcome:index',
);
global $config;
$config['mysql'] = array(
'prefix' => '',
'master' => array(
'host' => '',
'port' => '',
'username' => '',
'password' => '',
'database' => '',
),
'slaver' => array(
'host' => '',
'port' => '',
'username' => '',
'password' => '',
'database' => '',
),
);
config/redis.php
global $config;
$config['redis'] = array(
//'url路径'=>'模块路径:方法'
'enable' => true, //使用redis缓存
'host' => '127.0.0.1', //主机
'port' => 6379, //端口号
'password' => '', //密码
'expire' => 300, //过期时间(秒)
'database' => 7, //redis缓存使用的数据库
);
class Welcome extends Controller {
public function index(){
S("age", 12, 120);
$age = S("age");
$info = M("admin_users")->find($this->I("id"));
$this->assign("age", $age);
$this->assign("user", $info['realname']);
$this->assign("title", "RubyPHP");
$this->display("index");
}
}
{:$user}你好,您的年龄是{:$age},欢迎来到{:$title}
server
{
listen 80;
#listen [::]:80;
server_name swoole.fanghailiang.companyclub.cn ;
include none.conf;
location / {
proxy_pass http://localhost:9501;
}
}
url输入 http://swoole.fanghailiang.companyclub.cn/?id=4即可访问 2. cli模式运行 吧原来的控制器移到scripts目录下 controller/scripts/default/welcome.php
class Welcome extends Controller {
public function index(){
$this->assign("title", "RubyPHP");
$this->display("index");
}
}
命令行运行:php index.php default/welcome:index