[eluser]apolinux[/eluser]
Hi, I'm new in the forum, and sorry for my bad english. I'm developing a standalone app with ci, I mean it's a daemon app,which is always running. I had problems with this app because was crashing, with this fatal error:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in /var/www/html/quattromobile.net/ci/system/libraries/Model.php on line 60.
Basically, the program have a infinite loop, and in the start it connects to a DB, makes a single sql request (update) and after that disconnects.
after a long research process, I could find the solution to this problem. I had to put a breakpoints with the memory_get_usage function and I realize the memory script grows up after each loop. Therefore, soon or late it was to eat all the memory available.
The reason is because the object $this->db request more memory after each loop. My solution was creating the object at the beggining of the loop, then process stuffs, then close the database, and after that deleting the object $this->db, something like this:
Code:
while ( true and ! $this->manejador_senales_sistema->detectoAbortarExterno() )
{
$this->db = $this->load->database($this->config_bd , TRUE);
$this->procesarMos();
$this->db->close();
unset($this->db);
usleep($this->tiempo_espera_bucle);
}
I hope no more fatal errors appearing with this solution.
any comments are appreciated.