【发布时间】:2017-01-05 17:57:53
【问题描述】:
我有一个cron job,它调用以下codeigniter controller
但这耗时
其中计算和操作更多的操作(平均需要 5 分钟)
然后在数据库中插入值
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Mycron extends CI_Controller {
public function cron_function()
{
// simulate time cost operations
sleep(300); // 5 mint = 5 *60 = 300 sec
$this->load->database(); // line1
$this->db->reconnect(); // line2
$this -> db -> set ( 'source_id', '11');
$this -> db -> set ( 'title', 'TTL');
$query = $this -> db -> insert ( 'my_table' );
echo 'END ...';
}
}
我的问题
没有两条线 line1/line2
当数据库在操作消耗时间后尝试连接时,结果将是
SQL Error: 2006: MySQL server has gone away
然后当尝试使用 2 行将修复 RE_CONNECT 应用于数据库时
我们面对
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by
(output started at .../system/database/drivers/mysqli/mysqli_driver.php:392)
Filename: core/Common.php
Line Number: 568
Backtrace:
A PHP Error was encountered
Severity: Error
Message: Call to a member function real_escape_string() on boolean
Filename: mysqli/mysqli_driver.php
Line Number: 392
Backtrace:
【问题讨论】:
-
检查你的`my.cnf'中的
wait_timeout变量
标签: php codeigniter cron