CodeIgniter Forums
Server throws errors from time to time randomly - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Server throws errors from time to time randomly (/thread-58321.html)



Server throws errors from time to time randomly - El Forum - 06-03-2013

[eluser]predi[/eluser]
php 5.3.3
ci 2.1.3
server dedicated, cpu usage 5%, 7 gb ram free, mid traffic.

Server keeps throwing this error from time to time, when i randomly refresh the page.
I.e. i refresh the page - all works. Keep refreshing and randomly get this error:

Code:
Fatal error: Call to a member function item() on a non-object in /var/www/system/core/Router.php on line 110

I've investigated the Router.php 110 line, this part fails
Code:
if ($this->config->item('enable_query_strings')

Fails because $this->config is randomly NULL, so the config class just doesn't load-up randomly.
Why? How?!

I've modified the Router class, added force class load code:

Code:
if($this->config === NULL)
{
// force load and instantiate
require_once(BASEPATH.'core/Config.php');
$this->config = new CI_Config();

if($this->config === NULL)
  die('How can that be?');
}

Still get the error and "How can that be?" message randomly.
Anyone knows seems to be the problem?

UPDATE
I've modified the Router's constructor to the following:
Code:
/**
  * Constructor
  *
  * Runs the route mapping function.
  */
function __construct()
{
  $this->config =& load_class('Config', 'core');
  $this->uri =& load_class('URI', 'core');
  log_message('debug', "Router Class Initialized");
  
  if(ENVIRONMENT == 'development' && $this->config === NULL)
  {
   print_r($this->config);
   die('router->construct :: fail');
  }
}

Now i randomly get the die message "router->construct :: fail". So, why question is the same - why and how to fix?


Server throws errors from time to time randomly - El Forum - 06-03-2013

[eluser]predi[/eluser]
Made some nice crutches to make CI work properly...
Random error gone away, but still this is not a solution. Got to figure out what is the exact problem of the random failure.

Code:
/**
  * Constructor
  *
  * Runs the route mapping function.
  */
function __construct()
{
  $this->config =& load_class('Config', 'core');
  $this->uri =& load_class('URI', 'core');
  log_message('debug', "Router Class Initialized");
  
  if($this->config === NULL)
  {
   foreach($this as $key => $value)
   {
    unset($this->$key);
    $this->$key = $value;
   }
  }
}



Server throws errors from time to time randomly - El Forum - 07-04-2013

[eluser]Unknown[/eluser]
Have a same problem.
try restart apache problem in apache.
I do not know what exactly you want to change the settings in Apache, but reboot helps temporarily
for debian: sudo /etc/init.d/apache2 restart


php 5.3.3
ci 2.1.3
server dedicated, cpu usage low, 10 gb ram free, traffic 50000pages per day.