doucitan2544 2010-02-18 08:05
浏览 69
已采纳

如何通过CRON运行CodeIgniter文件?

I've tried the following method in the past:

<?php
set_time_limit(0);
$_SERVER['PATH_INFO'] = 'cron/controller/index';
$_SERVER['REQUEST_URI'] = 'cron/controller/index';
require_once('index.php');
?>

and putting this in a file in the codeigniter installation directory, calling it cron.php, and then invoking it via:

php /home/[username]/public_html/my_project/cron.php

If I type the URL to cron.php in my browser it works perfectly, however whenever its run via CRON I get a 404 error. Putting the following code in the show_404() function of CodeIgniter

function show_404($page = '')
{
   print_r($_SERVER);
   echo "

";
   die ($page);
}

results in getting the following output emailed to me:

Array
(
   [SHELL] => /bin/sh
   [MAILTO] => me@gmail.com
   [USER] => [me]
   [PATH] => /usr/bin:/bin
   [PWD] => /home/[me]
   [SHLVL] => 1
   [HOME] => /home/[me]
   [LOGNAME] => [me]
   [_] => /usr/bin/php
   [PHP_SELF] =>
   [REQUEST_TIME] => 1266479641
   [argv] => Array
       (
           [0] => /home/[me]/public_html/my_project/cron.php
       )

   [argc] => 1
   [PATH_INFO] => cron/controller/index
   [REQUEST_URI] => cron/controllers/index
)


home/[me]

Here I've [me] in place of my actual username.

Any ideas?

  • 写回答

6条回答 默认 最新

  • dongwei2610 2010-02-18 08:11
    关注

    The simplest way to run a cron via CodeIgniter is to make a cron URL available via your app.

    Then call it via wget

    wget -O - -q -t 1 http://www.example.com/cron/run
    

    Inside the controller you can then use a log to ensure the cron is not run too often i.e. if the Google robots trigger it by mistake.

    A second method would be to use lynx

    /usr/local/bin/lynx -source http://www.example.com/cron/run
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型