A simple way to reproduce this Killed error:
I was able to reproduce this error on Ubuntu 12.10 using PHP 5.3.10 .
Create a PHP script called m.php and save it:
<?php function repeat(){ repeat(); } repeat(); ?>
Run it:
el@apollo:~/foo$ php m.php Killed
The program takes up 100% of the processor for 15 seconds, then stops with the message Killed . Look dmesg | grep php dmesg | grep php and there are tips:
el@apollo:~/foo$ dmesg | grep php [2387779.707894] Out of memory: Kill process 2114 (php) score 868 or sacrifice child
So, in my case, the PHP program stopped and printed "Killed" because it ran out of memory due to an infinite loop.
Solutions:
- Increase the amount of available memory or the amount of memory available for this PHP program.
- Divide the problem into smaller pieces that work in sequence.
- Rewrite the program so that it has less memory requirements or is not so deep with recursion.
How not to get this problem again
If the code you wrote causes this error and you feel stuck and donβt understand why it is doing this, you need to revisit the main core behavior of PHP structures, loops and recursion, as well as how the memory allocated to satisfy these designs: http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/
Eric Leschinski Mar 13 '14 at 17:23 2014-03-13 17:23
source share