Does PHP set memory limits on arrays?

3.6k Views Asked by At

I have a weird memory problem in PHP. I think something is only allowing an array to be a maximum of 0.25M. It appears the script is only using up to around 6M before it crashes.

Here's the output from xdebug:

enter image description here

Here's the function it is calling. The result of the sql query is about 800 rows of text.

public function getOptions(){
    $sql = "select Opt,
                   Code,
                   Description
            from PCAOptions";

    $result = sqlsrv_query($this->conn,$sql);

    $arrayResult = array();
    echo ini_get('memory_limit'); //this confirms that my memory limit is high enough
    while($orderObject = sqlsrv_fetch_object($result,'PCA_Option')){
        array_push($arrayResult, $orderObject);
    }
    return $arrayResult;
}
3

There are 3 best solutions below

1
On BEST ANSWER

So, I don't know how or why this worked, but I fixed the problem by commenting out these two lines from my .htaccess file:

#    php_value memory_limit 1024M
#    php_value max_execution_time 18000

I did this because I noticed phpinfo() was returning different values for these settings in the two columns "master" and "local".

My php.ini had memory_limit=512M and max_execution_time=3000, whereas my .htacces file had the above values. I thought .htaccess would just override whatever was in php.ini but I guess it caused a conflict. Could this be a possible bug in php?

2
On

When working with 'big' scripts which i know will bypass my server PHP memory limits, i always set this variable at the beginning of the script. Works all the time.

ini_set("memory_limit","32M"); //Script should use up to 32MB of memory
0
On

There's a number of steps some PHP distributions, security packages, and web hosts take to prevent users from raising the PHP actual memory limit at runtime via ini_set. The most likely candidate is the suhosin security package.

This older Stack Overflow question has a number of other suggestions as well.