News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

memory_limit variable bug in product.php - empty mod_virtuemart_products

Started by jimijot, September 22, 2013, 11:48:32 AM

Previous topic - Next topic

jimijot

In product.php there is a line in class VirtueMartModelProduct definition:

$this->memory_limit = (int) substr(ini_get('memory_limit'),0,-1) -4; // 4 MB reserve

when function ini_get('memory_limit') returns -1 value that means unlimited memory - memory limit changes to int value -1. It makes an effect on empty output from getProduct function used in module  mod_virtuemart_products that compares currrent usage memory and memory limit. When that difference is negative (always) function getProduct  returns false.

Virtuemart version is 2.0.2.22d.

Temporary solution would be for example to replace the line:

$this->memory_limit = (int) substr(ini_get('memory_limit'),0,-1) -4; // 4 MB reserve

with code

      if ((int) substr(ini_get('memory_limit'),0,-1) > 0)
      {
         $this->memory_limit = (int) substr(ini_get('memory_limit'),0,-1) -4; // 4 MB reserve
      }
      else
      {
         $this->memory_limit = 1024;
      }




Milbo

Thank you, I use this way now


$memoryLimit = ini_get('memory_limit');
if($memoryLimit!=-1){
$this->memory_limit = (int) substr($memoryLimit,0,-1) -4; // 4 MB reserve
} else {
$this->memory_limit = 1024;
}


I changed it and use a function in VmConfig now


static function getMemoryLimit(){

$iniValue = ini_get('memory_limit');

if($iniValue===-1) return 2048; //We assume 2048MB as unlimited setting
$iniValue = strtoupper($iniValue);
if(strpos($iniValue,'M')!==FALSE){
$memory_limit = (int) substr($iniValue,0,-1);
} else if(strpos($iniValue,'K')!==FALSE){
$memory_limit = (int) substr($iniValue,0,-1) / 1024.0;
} else if(strpos($iniValue,'G')!==FALSE){
$memory_limit = (int) substr($iniValue,0,-1) * 1024.0;
} else {
$memory_limit = (int) $iniValue / 1048576.0;
}
return $memory_limit;
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

jimijot

I see the the changes are applied in version 2.0.24. Thank you for doing that. But i see the next problem, now function ini_get('memory_limit') returns 0 (in previous version VM returned -1) and I have similar effects in my testing enviroment (php 5.3.8) as before and many errors with memory limit.

I've found, that not only -1 but 0 also means unlimited memory. My proposal is to change "getMemoryLimit" function code:

orginal code:
if($iniValue===-1) return 2048;   //We assume 2048MB as unlimited setting

proposed code:
if($iniValue<=0) return 2048;   //We assume 2048MB as unlimited setting