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

Bad memory limit report break product display.

Started by Studio 42, November 17, 2016, 01:15:48 AM

Previous topic - Next topic

Studio 42

Tested on Vm 3.0.18, Joomla 3.6.4, php 5.6; 1go limit
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

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

advergroup

I am having the same issue with VirtueMart 3.2.12 and Joomla 3.8.6

Any ideas how I can resolve??

Studio 42

Quote from: 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??
If you can use 1024M or 2048M ....

Milbo

Quote from: Milbo on November 17, 2016, 13:44:53 PM
Thank you for the report

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


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


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;
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/


Milbo

Reading my code, I just noticed that


$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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

jcant

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:
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;
}

Studio 42

using 83886080 without any format is set as octets(bytes) i think, so only 80MO.
Use 2048M, 1024M or 1048576K

jcant

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?

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo


$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
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Rsn

Hello!
What is this for?
Quote
$ord = ord($u);
//Just numbers
if (($ord>=48)&&($ord<=57)) {
    $mLimit = (int)($mL);
} else {
    $mLimit = (int)substr($mL,0,-1);
}

Why not simple:

$mLimit = (int) $mL;

?

Casting to an integer type will automatically ignore the letters at the end of the string.