Esempio n. 1
0
 public function __construct()
 {
     $this->path = CACHE_PATH . 'file';
     \mPHP::inc(MPHP_PATH . 'inc/functions.php');
     //加载常用函数集
     $this->in('main');
 }
Esempio n. 2
0
 public function __construct($driver = 'file', $config = array())
 {
     \mPHP::inc(MPHP_PATH . 'inc/functions.php');
     //加载常用函数集
     $driver = "cache\\{$driver}";
     $this->cache = M($driver, $config);
 }
Esempio n. 3
0
 public function indexAction()
 {
     //调试状态关闭缓存功能,默认为调试状态。0:非调试状态 1:调试状态
     //在初始化mPHP前,可以通过配置$GLOBALS['CFG']['debug']来设定
     //初始化mPHP后,可以通过配置mPHP::$debug来设定
     mPHP::$debug = 0;
     //初始化阶段mPHP已经声明了视图类
     //mPHP::$view = new view();
     $view = mPHP::$view;
     $tpl = 'view';
     //模版名称
     $file = CACHE_PATH . "html/{$tpl}.html";
     //缓存html文件保存位置
     $time = 5;
     //缓存时间(秒)
     $cache = $view->cache($file, $time);
     if ($cache) {
         return true;
     }
     //缓存有效期内直接返回
     sleep(1);
     //模拟耗时操作
     $view->data['title'] = 'mPHP视图类缓存demo ';
     $view->data['h'] = 'hello ';
     $view->data['w'] = 'world ';
     $view->loadTpl($tpl);
     //加载模版
     highlight_file(__FILE__);
 }
Esempio n. 4
0
 public function __construct($arrConfig)
 {
     mPHP::inc(MPHP_PATH . 'inc/functions.php');
     //加载常用函数集
     $type = $arrConfig['type'];
     $name = $arrConfig['dbname'];
     $host = $arrConfig['host'];
     $port = $arrConfig['port'];
     $this->link = "{$type}:host={$host};dbname={$name}";
     $this->user = $arrConfig['user'];
     $this->pass = $arrConfig['password'];
     $this->charset = $arrConfig['charset'];
     $this->connect();
 }
Esempio n. 5
0
 public function strImage($str)
 {
     // 建立一幅 100X30 的图像
     $im = imagecreate(55, 30);
     // 白色背景和蓝色文本 D6BB86
     //$bg = imagecolorallocate($im, 0xd6, 0xbb, 0x86);
     $bg = imagecolorallocate($im, 0xff, 0xff, 0xff);
     $textcolor = imagecolorallocate($im, 0, 0, 0);
     // 把字符串写在图像左上角
     imagestring($im, 5, 5, 5, $str, $textcolor);
     // 输出图像
     mPHP::header('Content-Type', 'image/png');
     imagepng($im);
 }
 public function indexAction()
 {
     //调试状态关闭缓存功能,默认为调试状态。0:非调试状态 1:调试状态
     //在初始化mPHP前,可以通过配置$GLOBALS['CFG']['debug']来设定
     //初始化mPHP后,可以通过配置mPHP::$debug来设定
     mPHP::$debug = 0;
     //初始化阶段mPHP已经声明了视图类
     //mPHP::$view = new view();
     $view = mPHP::$view;
     $view->is_mini_html = true;
     //启用压缩html功能,默认关闭。调试状态下被禁用
     $view->data['title'] = 'mPHP压缩html代码demo';
     $tpl = 'mini';
     //模版名称
     $view->loadTpl($tpl);
     //加载模版
     echo '<h1>控制器源代码:</h1><hr />';
     highlight_file(__FILE__);
 }
 public function indexAction()
 {
     //调试状态关闭缓存功能,默认为调试状态。0:非调试状态 1:调试状态
     //在初始化mPHP前,可以通过配置$GLOBALS['CFG']['debug']来设定
     //初始化mPHP后,可以通过配置mPHP::$debug来设定
     mPHP::$debug = 0;
     //默认值为0:使用PHP正则表达式压缩代码
     // 1:java环境启用yuicompressor压缩
     // 如果环境支持java,可以下载yuicompressor-2.4.8.jar放置LIBS_PATH目录中
     // 文档地址:http://yui.github.io/yuicompressor/
     mPHP::$CFG['java'] = 1;
     //初始化阶段mPHP已经声明了视图类
     //mPHP::$view = new view();
     $view = mPHP::$view;
     $view->is_merger = true;
     //启用js、css文件合并压缩功能,默认关闭。调试状态下被禁用
     $view->data['title'] = 'mPHP合并压缩js、css代码demo';
     $tpl = 'merger';
     //模版名称
     $view->loadTpl($tpl);
     //加载模版
     echo '<h1>控制器源代码:</h1><hr />';
     highlight_file(__FILE__);
 }
Esempio n. 8
0
<?php

define('INIT_MPHP', 'mo2g.com');
//常量值可以随便定义
define('INDEX_PATH', __DIR__ . '/');
define('MPHP_PATH', realpath(INDEX_PATH . '../../') . '/');
//框架根目录
include MPHP_PATH . 'mPHP.php';
$mPHP = mPHP::init();
$mPHP->run();
Esempio n. 9
0
 public function free()
 {
     --$this->connection_num;
     $this->idle_pool[] = mPHP::$db;
     mPHP::$db = false;
 }
Esempio n. 10
0
 public static function dirCache()
 {
     mPHP::inc(MPHP_PATH . 'inc/functions.php');
     //加载常用函数集
     if ($arrDir = C('cache', 'html_cache_dir')) {
         if (is_dir(CACHE_PATH . 'html')) {
             foreach ($arrDir as $key => $value) {
                 $dir = CACHE_PATH . 'html/' . $key . '/';
                 if (is_dir($dir)) {
                     $i = 0;
                     while ($i < $value) {
                         if (!is_dir($dir . $i)) {
                             mkdir($dir . $i);
                         }
                         ++$i;
                     }
                 } else {
                     mkdir($dir);
                     $i = 0;
                     while ($i < $value) {
                         if (!is_dir($dir . $i)) {
                             mkdir($dir . $i);
                         }
                         ++$i;
                     }
                 }
             }
         } else {
             mkdir(CACHE_PATH . 'html');
             dirCache();
         }
     }
 }
Esempio n. 11
0
 public function cache($file, $cacheTime)
 {
     $this->is_cache = true;
     $time = $_SERVER['REQUEST_TIME'];
     $createTime = file_exists($file) ? filemtime($file) : 0;
     if ($createTime + $cacheTime >= $time && !mPHP::$debug) {
         $createTime = date("D, d M Y H:i:s", $createTime);
         mPHP::header('Cache-Control', 'max-age=0');
         mPHP::header('Last-Modified', $createTime);
         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $createTime) {
             mPHP::status(304);
         } else {
             include $file;
         }
         mPHP::_exit();
         return true;
     }
     return false;
 }
Esempio n. 12
0
 public function onWorkerStart()
 {
     include MPHP_PATH . 'mPHP.php';
     self::$mPHP = mPHP::init();
 }
Esempio n. 13
0
function P($val, $true = true)
{
    echo '<pre>';
    if (is_array($val)) {
        print_r($val);
    } else {
        var_dump($val);
    }
    echo '</pre>';
    if ($true) {
        mPHP::_exit();
    }
}