From 10ee91b93e36956e38da620d1899d0504d83e317 Mon Sep 17 00:00:00 2001 From: Tinywan <756684177@qq.com> Date: Sun, 30 Oct 2016 09:24:28 +0800 Subject: [PATCH] =?UTF-8?q?thinkphp3.2=20cli=E6=A8=A1=E5=BC=8F=E7=9A=84?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E4=BD=BF=E7=94=A8=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Backend/Home/Common/function.php | 43 +++++++++++++++++ .../Controller/DataBaseController.class.php | 28 +++++++++-- admin.php | 9 ++-- admin_bak.php | 47 +++++++++++++++++++ 4 files changed, 117 insertions(+), 10 deletions(-) create mode 100644 Backend/Home/Common/function.php create mode 100644 admin_bak.php diff --git a/Backend/Home/Common/function.php b/Backend/Home/Common/function.php new file mode 100644 index 0000000..22b9859 --- /dev/null +++ b/Backend/Home/Common/function.php @@ -0,0 +1,43 @@ +'; + // 如果是boolean或者null直接显示文字;否则print + if (is_bool($data)) { + $show_data = $data ? 'true' : 'false'; + } elseif (is_null($data)) { + $show_data = 'null'; + } else { + $show_data = print_r($data, true); + } + $str .= $show_data; + $str .= ''; + echo $str; +} + +/** + * php cli模式执行php文件 + * 测试 + */ +function cli_test() +{ + $count = 0; + while(true){ + $count++; + echo $count."\r\n"; + if($count > 10){ + break; + } + sleep(3); + } + echo 'done'; +} \ No newline at end of file diff --git a/Backend/Home/Controller/DataBaseController.class.php b/Backend/Home/Controller/DataBaseController.class.php index 1cdd1fb..ff23c96 100644 --- a/Backend/Home/Controller/DataBaseController.class.php +++ b/Backend/Home/Controller/DataBaseController.class.php @@ -119,12 +119,32 @@ public function createRedis() return $rPushResul; } - public function executeFunction() + /** + * php cli模式执行php文件 + * 模拟队列发送邮件 + */ + public function executeCli() + { + $dir = 'D:\wamp\bin\php\php5.5.12>php.exe'; + exec("D:\wamp\bin\php\php5.5.12>php.exe ../cli_test.php"); + } + + /** + * php cli模式执行php文件 + * D:\wamp\bin\php\php5.5.12>php.exe ../cli_test.php + */ + public function cli_test() { - for ($x=0; $x<=10000; $x++) - { - $this->createRedis(); + $count = 0; + while(true){ + $count++; + file_put_contents("./test_result.txt",$count."\r\n",FILE_APPEND); + if($count > 10){ + break; + } + sleep(3); } + echo 'done'; } diff --git a/admin.php b/admin.php index 34745f8..c702f10 100644 --- a/admin.php +++ b/admin.php @@ -31,13 +31,10 @@ * new:http://serverName/home.php/index */ //define('BIND_CONTROLLER','Index'); +//php-cli http://www.thinkphp.cn/topic/34761.html // 定义应用目录 -define('APP_PATH','./Backend/'); +define('APP_PATH',dirname(__FILE__).'/Backend/'); // 引入ThinkPHP入口文件 -require './ThinkPHP/ThinkPHP.php'; - - - -// 亲^_^ 后面不需要任何代码了 就是如此简单 +require dirname( __FILE__).'/ThinkPHP/ThinkPHP.php'; diff --git a/admin_bak.php b/admin_bak.php new file mode 100644 index 0000000..f2c71f9 --- /dev/null +++ b/admin_bak.php @@ -0,0 +1,47 @@ + + + + +// +---------------------------------------------------------------------- + +// 应用入口文件 + +// 检测PHP环境 +if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); + +// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false +define('APP_DEBUG',True); + +/** + * 绑定Home模块到当前入口文件(3.2.1以上版本写法) + * old:http://serverName/index.php/Home/Index/index + * new:http://serverName/home.php/Index/index + */ +//define('BIND_MODULE','Home'); + + +/** + * 绑定Index控制器到当前入口文件(3.2.1以上版本写法) + * old:http://serverName/index.php/Home/Index/index + * new:http://serverName/home.php/index + */ +//define('BIND_CONTROLLER','Index'); + +// 定义应用目录 +define('APP_PATH','./Backend/'); + +// 引入ThinkPHP入口文件 +require './ThinkPHP/ThinkPHP.php'; + + + +// 亲^_^ 后面不需要任何代码了 就是如此简单 +