Generic “Killed” error in PHP script

I am working on a CRON job that invokes a PHP script which does a lot of database work with loops.

It executes properly when I limit the data set, but when I run it against the full data set, the script errors out with a message:


set_time_limit is (0) and memory_limit is (-1)

Here is the code section where it consistently dies:

echo "I'm in _getMemberDemographicAttrsn";
if (! empty ( $member_id )) {
    $query .= ' AND member_id = ' . $member_id;

$result = mysql_query ( $query, $this->_db );
if ($result) {
    while ( $rule = mysql_fetch_assoc ( $result ) ) {
        $rules [] = $rule;
    if (! empty ( $rules )) {
        mysql_free_result ( $result );
        echo "I'm leaving _getMemberDemographicAttrsn";
        return $rules;

The output looks like this:

I'm in _getMemberDemographicAttrs<br/>
I'm leaving _getMemberDemographicAttrs<br/>
I'm in _getMemberDemographicAttrs<br/>
I'm leaving _getMemberDemographicAttrs<br/>
I'm in _getMemberDemographicAttrs<br/>

I’ve never seen this generic Killed error message and I’m wondering what is causing it to be killed?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You might be triggering the Linux out-of-memory (OOM) killer. Check dmesg for messages about it. It says which process was killed when this happens.

Method 2

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:

    function repeat(){

Run it:

<a href="" class="__cf_email__" data-cfemail="2b4e476b4a5b44474744">[email protected]</a>:~/foo$ php m.php

The program takes 100% CPU for about 15 seconds then halts with the Killed message. Look at dmesg | grep php and there are clues:

<a href="" class="__cf_email__" data-cfemail="a8cdc4e8c9d8c7c4c4c7">[email protected]</a>:~/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.


  1. Increase the amount of RAM available or amount of memory available to this PHP program.
  2. Break down the problem into smaller chunks that operate sequentially.
  3. Rewrite the program so it has smaller memory requirements or doesn’t go so deep with recursion.

Method 3

In my case on CloudLinux, PHP 7.1, it occurred when 2 processes were reading and writing to the same file without locks.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x