I have a cron job
which call the following codeigniter controller
But it is time costly
Which calculate and operate more operations (on average need 5 minutes)
Then insert values on database
<?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 ...';
}
}
My issue
Without both lines line1/line2
When database try to connect after consumed time on operationsthe result will be
SQL Error: 2006: MySQL server has gone away
Then when try to apply the fix RE_CONNECT to database by using 2 lines
We face
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: