我正在尝试在 codeigniter 和 hostgator 中运行 follow cron 作业
/usr/bin/php /home/username/public_html/index.php cronjob contact martin
但是没有任何反应,我收到以下邮件:
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined index: REMOTE_ADDR</p>
<p>Filename: core/Input.php</p>
<p>Line Number: 351</p>
<p>Severity: Warning</p>
<p>Message: Cannot modify header information - headers already sent by (output started at /home/iglesias/public_html/mysite.com/system/core/Exceptions.php:185)</p>
<p>Filename: libraries/Session.php</p>
<p>Line Number: 675</p>
我的controller如下(简单发邮件测试)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cronjob extends CI_Controller {
function __construct()
{
parent::__construct();
$this->cron();
}
function cron()
{
if(!$this->input->is_cli_request())
{
die();
}
}
function contact($name)
{
$this->load->library('email');
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from('test@gmail.com', $name);
$this->email->to('test2@gmail.com');
$this->email->subject('test');
$this->email->message('test sent');
$this->email->send();
}
}
我做错了什么吗?我将衷心感谢您的帮助。
当从 URL 调用时,我更改了 .htaccess 以删除 index.php,我不知道这是否与此有关。
谢谢
最佳答案
我的答案是很久以后才出现的,但它可以帮助其他人。 这个错误显然是众所周知的,但只有一个快速修复:http://ellislab.com/forums/viewthread/227672/ 它说当您自动加载 session 库时会发生这种情况,它会调用未初始化的 CI_Input::ip_address() 或类似的东西。 快速修复在输入类中(core/Input.php 第 351 行(CI 2.1.2)):
$this->ip_address = $_SERVER['REMOTE_ADDR'];
成为:
if(isset($_SERVER['REMOTE_ADDR']))
$this->ip_address = $_SERVER['REMOTE_ADDR'];
else
$this->ip_address = '0.0.0.0';
希望这对您有所帮助。
关于php - 在 CodeIgniter 和 Hostgator 中运行 cron 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15768231/