通过 Cpanel 的 CodeIgniter Cron 作业 [英] CodeIgniter Cron Job through Cpanel

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

问题描述

好的,我查看了所有其他线程,并完全完成了他们所做的以及手册中的说明,但我终生无法弄清楚这一点.cron 作业的结果正在通过电子邮件发送到我的一封电子邮件.它所做的只是打印出布局的 html 标记......并打印基页内容......就像它没有注册任何东西.

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

那是我的命令行.. 我也尝试用 user/local/bin/php 替换 php,但没有奏效.问题是我有其他 cron 作业运行程序 PHP 代码,这些代码可以很好地与 php path/to/cron.php 一起工作......但它不会与 CI 一起工作......

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..

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

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';
}

这里是方法的逻辑:

//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.

在打开控制器 Cron 类之前,它是否位于控制器的顶部有关系吗?

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');

推荐答案

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

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

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

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

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

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