VirtueMart Forum

VirtueMart 2 + 3 => Virtuemart Development and bug reports => Topic started by: Studio 42 on November 17, 2016, 01:15:48 am

Title: Bad memory limit report break product display.
Post by: Studio 42 on November 17, 2016, 01:15:48 am
Tested on Vm 3.0.18, Joomla 3.6.4, php 5.6; 1go limit
Code: [Select]
if ($this->memory_limit<$mem = round(memory_get_usage(FALSE)/(1024*1024),2)) {
vmdebug ('Memory limit reached in model product getProduct('.$virtuemart_product_id.'), consumed: '.$mem.'M');
vmError ('Memory limit reached in model product getProduct() ' . $virtuemart_product_id);
return false;
}
use bad memory usage and don't load any products !
Only on using PHP 7.0, it work but report :
$this->memory_limit : -3 (negative value)
rounded memory_get_usage : 5.5
So it work only because php 7 report negative value
the string value is for memory limit is "1G"  (one giga) as default perhaps is your convertion bad when server limit use G and not M ?

This is the virtuemart debug :

vmdebug Start used Ram 4.5M
vmdebug getVendorId normal shopper
vmdebug vmTime: sortSearchQuery products: 0.0241389274597168
vmdebug Memory limit reached in model product getProduct(7225), consumed: 4.9M
vmdebug Memory limit reached in model product getProduct(6667), consumed: 4.9M
vmdebug Memory limit reached in model product getProduct(6540), consumed: 4.9M
vmdebug Memory limit reached in model product getProduct(7080), consumed: 4.9M
vmdebug Memory limit reached in model product getProduct(7079), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(6998), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(6999), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(7156), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(7120), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(6957), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(6994), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(6995), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(7052), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(7049), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(7113), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(7115), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(7114), consumed: 4.91M
vmdebug Memory limit reached in model product getProduct(6595), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(1377), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(7123), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(7283), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(7282), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(7154), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(7088), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(7087), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(7098), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(7101), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(7032), consumed: 4.92M
vmdebug Memory limit reached in model product getProduct(7100), consumed: 4.92M
Title: Re: Bad memory limit report break product display.
Post by: Milbo on November 17, 2016, 13:44:53 pm
Thank you for the report

Title: Re: Bad memory limit report break product display.
Post by: advergroup on April 17, 2018, 19:38:09 pm
I am having the same issue with VirtueMart 3.2.12 and Joomla 3.8.6

Any ideas how I can resolve??
Title: Re: Bad memory limit report break product display.
Post by: Studio 42 on April 17, 2018, 21:30:04 pm
I am having the same issue with VirtueMart 3.2.12 and Joomla 3.8.6

Any ideas how I can resolve??
If you can use 1024M or 2048M ....
Title: Re: Bad memory limit report break product display.
Post by: Milbo on April 20, 2018, 00:07:29 am
Thank you for the report

I am quite sure I worked on that. Maybe you find the missing piece, Patrick.

Code: [Select]
if ($this->memory_limit<$mem = memory_get_usage(FALSE)) {

$this->memory_limit is set with $this->memory_limit = VmConfig::getMemoryLimitBytes(); and here is the code

Code: [Select]
static function getMemoryLimitBytes(){
static $mLimit;
if($mLimit===null){
$mL = ini_get('memory_limit');
$mLimit = 0;
if(!empty($mL)){
$u = strtoupper(substr($mL,-1));
$mLimit = (int)substr($mL,0,-1);
if($mLimit>0){
if($u == 'M' or $u == 'MB'){
$mLimit *= 1048576;
} else if($u == 'G' or $u == 'GB'){
$mLimit *= 1073741824;
} else if($u == 'K' or $u == 'KB'){
$mLimit *= 1024;
}

$mTest = $mLimit - 5242880; // 5 MB reserve

if($mTest<=0){
$m = 'Increase your php memory limit, which is must too low to run VM, your current memory limit is set as '.$mL.' = '.$mLimit.'B';
vmError($m,$m);
}
}
}

if($mLimit<=0) $mLimit = 2142240768;
vmdebug('My Memory Limit in Bytes '.$mLimit);
}

return $mLimit;
}
Title: Re: Bad memory limit report break product display.
Post by: franzytcha on May 02, 2018, 21:44:24 pm
Any solution?
Title: Re: Bad memory limit report break product display.
Post by: Milbo on May 02, 2018, 22:02:06 pm
Reading my code, I just noticed that

Code: [Select]
$mLimit = (int)substr($mL,0,-1);
if($mLimit>0){
if($u == 'M' or $u == 'MB'){
$mLimit *= 1048576;
} else if($u == 'G' or $u == 'GB'){
So $u can never be GB. Because $u is always just the last char. Maybe there is the problem.
Title: Re: Bad memory limit report break product display.
Post by: jcant on August 07, 2018, 09:41:05 am
in my case
memory_limit = 83886080 (in php.ini)

static function getMemoryLimitBytes() (from administrator\components\com_virtuemart\helpers\config.php)
returned 8388608 and I had many "Memory Limit" errors.

I did some changes:
Code: [Select]
static function getMemoryLimitBytes(){
static $mLimit;
if($mLimit===null){
$mL = ini_get('memory_limit');
$mLimit = 0;
if(!empty($mL)){

$u = strtoupper(substr($mL,-1));

if ((ord($u)>=48)&&(ord($u)<=57)) $mLimit = (int)($mL);
else $mLimit = (int)substr($mL,0,-1);

if($mLimit>0){
if($u == 'M' or $u == 'MB'){
$mLimit *= 1048576;
} else if($u == 'G' or $u == 'GB'){
$mLimit *= 1073741824;
} else if($u == 'K' or $u == 'KB'){
$mLimit *= 1024;
}

$mTest = $mLimit - 5242880; // 5 MB reserve

if($mTest<=0){
$m = 'Increase your php memory limit, which is must too low to run VM, your current memory limit is set as '.$mL.' = '.$mLimit.'B';
vmError($m,$m);
}
}
}

if($mLimit<=0) $mLimit = 2142240768;
vmdebug('My Memory Limit in Bytes '.$mLimit);
}

return $mLimit;
}
Title: Re: Bad memory limit report break product display.
Post by: Studio 42 on August 07, 2018, 10:36:14 am
using 83886080 without any format is set as octets(bytes) i think, so only 80MO.
Use 2048M, 1024M or 1048576K
Title: Re: Bad memory limit report break product display.
Post by: jcant on October 22, 2018, 07:32:55 am
Thank you for reply.
This limit (83886080) is setted up by hoster-system automatically (site is at the virtual hosting) and I can see it only by using phpinfo() - I can't change this setting.
I can't update VM component - it will delete my changes and VM component failture to work again.
Is it chance to have this (or more correct and beautiful) changes in next update?
Title: Re: Bad memory limit report break product display.
Post by: Milbo on October 22, 2018, 21:22:14 pm
Added
Quote
(ord($u)>=48)&&(ord($u)<=57)
Seems to be a very nice and elegant method to differ a character from a normal digit.
Title: Re: Bad memory limit report break product display.
Post by: Milbo on October 22, 2018, 22:54:30 pm
Code: [Select]
$u = strtoupper(substr($mL,-1));
$u2 = strtoupper(substr($mL,-2,1));
$ord = ord($u);
$ord2 = ord($u2);
//Just numbers
if (($ord>=48)&&($ord<=57)) {
$mLimit = (int)($mL);
} else if (($ord2>=48)&&($ord2<=57)){
$mLimit = (int)substr($mL,0,-1);
} else {
$mLimit = (int)substr($mL,0,-2);
$u = $u2.$u;
}

is my new solution. Works then also for MB for example