CodeIgniter Cron Job通过Cpanel [英] CodeIgniter Cron Job through Cpanel

查看:189
本文介绍了CodeIgniter Cron Job通过Cpanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定我查看每一个其他线程,并做了他们做了什么,它在手册中说的,我不能把这一切都为我的生活。
cron作业的结果正通过电子邮件发送给我的一封电子邮件。所有它正在做的是打印的HTML标记的布局...和打印基本页面内容...这就像它不注册任何东西。

  php /home/jdstable/public_html/dev/index.php cron decrease_pets_stats 

这是我的命令行..我试着用用户/本地/ bin / php的东西替换php,它没有工作。事情是,我有其他cron工作运行的程序PHP代码工作FINE与php路径/到/ cron.php ...但它不能使用CI ..



我的控制器是Cron,我的方法是decrease_pets_stats ..

  //减少pets stats 
public function decrease_pets_stats(){
$ this-> load-> model('Cron_model','cron');
$ this-> cron-> decrease_pets_stats();
echo'减少宠物数据';
}

这里是方法的逻辑:

  //减少pets stats 
//每小时运行
public function decrease_pets_stats(){
$ this-> db-> set('hunger','hunger - 5');
$ this-> db-> set('happiness','happiness - 5');
$ this-> db-> set('loyalty','loyalty -5');
$ this-> db-> update('user_creature');
}

有没有人知道为什么它只是打印布局标记?我的构造函数看起来像这样:

  public function __construct(){
parent :: __ construct
if(!$ this-> input-> is_cli_request())show_error('不允许直接访问');

$ this-> load-> model('Cron_model','cron');
}

我的父构造函数拥有相当多的东西如果他们登录,获取用户信息出现在每个页面上。



这是否重要,如果这是在控制器的顶部,甚至打开控制器Cron类?

  if(!defined('BASEPATH'))exit('不允许直接脚本访问'); 

您使用的默认PHP安装可能是编译为CGI-FCGI,不是为CLI,它取决于您的主机和/或服务器,但你需要搜索您的PHP安装的命令行界面,然后在您的cron作业中使用它我在Hostmonster完全相同的问题,我的cron命令最终是:

  / ramdisk / bin / php5-cli〜/ public_html / sitefolder / index.php控制器方法

对我来说,我需要的PHP在 / ramdisk / bin / php5 -cli


Ok I looked at every other thread and have done exactly what they've done and what it says in the manual and I can NOT figure this out for the life of me. The results of the cron job are being emailed to one of my emails. ALL it is doing is printing out the html markup of the layout... And printing the base page content... It's like it's not registering anything.

php /home/jdstable/public_html/dev/index.php cron decrease_pets_stats

That's my command line.. I tried replacing php with the user/local/bin/php thing as well and it didn't work. The thing is is that I have other cron jobs running off procedural PHP code that work FINE with php path/to/cron.php... But it won't work with CI..

My controller is Cron and my method is decrease_pets_stats..

//decrease pets stats
public function decrease_pets_stats() {
$this->load->model('Cron_model', 'cron');
    $this->cron->decrease_pets_stats();
    echo 'Decreased pet stats';
}

And here is the logic of the method:

//decrease pets stats
//runs every hour
public function decrease_pets_stats() {
    $this->db->set('hunger', 'hunger - 5');
    $this->db->set('happiness', 'happiness - 5');
    $this->db->set('loyalty', 'loyalty - 5');
    $this->db->update('user_creature');
}

Does anyone have any idea why it's just printing the layout markup? My constructor looks like this:

public function __construct() {
        parent::__construct();
        if( ! $this->input->is_cli_request()) show_error('Direct access is not allowed');

        $this->load->model('Cron_model', 'cron');
    }

And my parent constructor holds quite a bit of stuff (loading helpers and libraries along with getting the user information to appear on each page if they are logged in.

Does it matter if this is at the top of the controller before even opening the controller Cron class?

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

解决方案

The default PHP install you are using was probably compiled as CGI-FCGI, not for CLI. It depends on your host and/or server, but you'll need to search for your PHP install for the command line interface, and then use that in your cron job. I had the exact same problem on Hostmonster, and my cron command ended up being:

/ramdisk/bin/php5-cli ~/public_html/sitefolder/index.php controller method

For me, the PHP I needed was in /ramdisk/bin/php5-cli.

这篇关于CodeIgniter Cron Job通过Cpanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆