Andy's Blog » CodeIgniter 命令行, codeigniter cron, cron job, request_uri, cronjob, path_info, codeigniter Cron job, codeigniter set_time_limit, codeigniter cli cron, codeigniter request_uri, codeigniter cron www, codeigniter 命令行 REMOTE_ADDR, codeigniter crontab, 命令行执行 CI框架 » CodeIgniter & Cron 命令行运行 CodeIgniter

CodeIgniter & Cron 命令行运行 CodeIgniter

方法1:直接修改 $_SERVER['PATH_INFO'] 和 $_SERVER['REQUEST_URI'] 以改变 controller

/* make sure this isn't called from a web browser */
if (isset($_SERVER['REMOTE_ADDR'])) die('Permission denied.');
/* set the controller/method path */
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = '/cron/purge_cache';
/* raise or eliminate limits we would otherwise put on http requests */
ini_set('memory_limit', '256M');
/* call up the framework */

方法2:用 $argv 获取参数,转换成controller

 * only a few lines of code will make the best web framework
 * function on the command line

/* we don't need to be limited by...normal limitations */
ini_set('memory_limit', '256M');
/* make sure this isn't being called by a web browser */
if (isset($_SERVER['REMOTE_ADDR'])) die('Permission denied.');
/* set some constants */
define('CMD', 1);
/* manually set the URI path based on command line arguments... */
unset($argv[0]); /* ...but not the first one */
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = '/' . implode('/', $argv) . '/';


./cli.php cron purge_cache

Incoming search terms:

Tags: cron, cron job, CodeIgniter, 命令行, SSH, argv, CLI, PATH_INFO, REQUEST_URI