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:
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;
}
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.
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.”
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.
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With