Generic "Killed" error in PHP script
Simple way to reproduce this Killed
error:
I was able to reproduce this error on Ubuntu 12.10
with 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.phpKilled
The program takes 100% CPU for about 15 seconds then halts with the Killed
message. Look at dmesg | grep php
and there are clues:
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 halted and printed "Killed" because it ran out of memory due to an infinite loop.
Solutions:
- Increase the amount of RAM available or amount of memory available to this PHP program.
- Break down the problem into smaller chunks that operate sequentially.
- Rewrite the program so it has smaller memory requirements or doesn't go so deep with recursion.