Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does PHP set memory limits on arrays?

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;
}
like image 562
Westwick Avatar asked Jan 18 '13 17:01

Westwick


People also ask

Does PHP array have limit?

There is no max on the limit of an array. There is a limit on the amount of memory your script can use. This can be changed in the 'memory_limit' in your php. ini configuration.

What are PHP limits?

The PHP memory_limit is the maximum amount of server memory that each PHP script is allowed to consume. Per the PHP documentation: “This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts from eating up all available memory on a server.”

Can PHP arrays hold different data types?

Not going to put oil on the fire of the PHP Arrays are no arrays here… But yes, you can put different variable types (string, int, …) together in a PHP thing called Array.

Does PHP support array?

In PHP, there are three types of arrays: Indexed arrays - Arrays with a numeric index. Associative arrays - Arrays with named keys. Multidimensional arrays - Arrays containing one or more arrays.


1 Answers

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?

like image 90
Westwick Avatar answered Oct 11 '22 00:10

Westwick