PHP script is killed without explanation

前端 未结 5 641
失恋的感觉
失恋的感觉 2021-01-19 17:22

I\'m starting my php script in the following way:

bash  
cd \'path\'   
php -f \'scriptname\'.php

There is no output while the php script i

5条回答
  •  不思量自难忘°
    2021-01-19 17:51

    You could be running out of memory in the PHP script. Here is how to reproduce that error:

    I'm doing this example on Ubuntu 12.10 with PHP 5.3.10:

    Create this PHP script called m.php and save it:

    
    

    Run it:

    el@apollo:~/foo$ php m.php
    Killed
    

    The program takes 100% CPU for about 15 seconds then stops. 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 printed "Killed" and halted because it ran out of memory due to an infinite loop.

    Solutions:

    1. Increase the amount of RAM available.
    2. Break down the problem set into smaller chunks that operate sequentially.
    3. Rewrite the program so it has a much smaller memory requirements.

提交回复
热议问题