Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How did my script run out of memory and execution time at the same time?

Tags:

php

I knew I was going to run out of something, since I was running a very long task. That's not the problem.

I am just curious, how did I get both errors at the same time?

Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 71 bytes) in...

--

Fatal error: Maximum execution time of 300 seconds exceeded in Unknown on line 0

Shouldn't the first "fatal" error halt execution? I am running APC and php 5.2.6.

EDIT: Here is a screenshot

like image 797
Ben Avatar asked Oct 05 '22 08:10

Ben


1 Answers

It might be that you're running into a race-condition here.

It basically works for example triggering a FATAL in the shutdown function for the memory and a FATAL for the timeout earlier triggering the shutdown function:

register_shutdown_function(function() {
    # consume all memory
    echo "break my pain\n";
    $a = ['hello'];
    while($a[] = $a);
});

set_time_limit(1);
while(1) usleep(100);

It also works the other way round, first triggering the FATAL for the memory, then the FATAL for the timeout in the shutdown function:

register_shutdown_function(function() {
    set_time_limit(1);
    while(1) usleep(100);
});

ini_set('memory_limit', '1');
$a = array_fill(0, 1024, 'hello');
while($a[] = $a);

This does not yet 100% explain what happens inside Codeigniter, however I'd say the query takes too long therefore after returning triggering the execution time limit as well. This is somewhat hard to reproduce because of your older PHP version. If I now eval PHP code, I get the message that the code was eval'ed and in which line I find that eval command (PHP 5.4). Try to reproduce with PHP 5.4 to gain more information. You will also greatly benefit from the speed improvements we've seen since PHP 5.2. You're missing a lot.

Earlier:

Fatal error: Maximum execution time of 300 seconds exceeded in Unknown on line 0

This smells like a startup error.

What has triggered your first error is hard to say, you cutted it off. Either you have got eval'ed code here which might have been handled partly a-part via APC you could see two fatal errors in the same script.

However, try without APC if you can reproduce it. If you still can, please report it in the PHP bugtracker.

If you can't, please report the problem with the APC bugtracker.

Edit: Just seeing PHP 5.2.6, you might need to report and fix it your own though ;) - Try to reproduce with the current stable PHP version as well then.

like image 180
hakre Avatar answered Oct 10 '22 03:10

hakre