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 report : Increase your php memory limit, which is must too low to run VM

Started by Studio 42, February 16, 2017, 18:24:02 PM

Previous topic - Next topic

Studio 42

If you set php memory limit too 2048M, you get message
QuoteIncrease your php memory limit, which is must too low to run VM ...

in config.php replace :
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;
}
$mLimit = (int) $mLimit - 5242880; // 5 MB reserve
if($mLimit<=0){
$mLimit = 1;
$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 = 2147483648;
vmdebug('My Memory Limit in Bytes '.$mLimit);
}

return $mLimit;
}


with :


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;
}
if($mLimit<5242880){
$mLimit = 1;

$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 = 2147483648;
vmdebug('My Memory Limit in Bytes '.$mLimit);
}

return $mLimit;
}


(int) $mLimit - 5242880 do not return the right calculation and give a negative value

Milbo

The error is the cast to int, which is too small for the 2048 MB expressed in bytes.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Studio 42

if($mLimit<5242880){ work always

$mLimit = (int) $mLimit - 5242880; // 5 MB reserve
if($mLimit<=0){

do not work always

Milbo

Studio, your code is wrong. The original code delivers the amount of mb available for VM. the limit is then set to 1, and so on.

the error is mainly "(int) $mLimit - 5242880;"
cast $mLimit to int, which has as biggest size http://php.net/manual/de/language.types.integer.php

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18, except on Windows prior to PHP 7, where it was always 32 bit. PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, maximum value using the constant PHP_INT_MAX since PHP 5.0.5, and minimum value using the constant PHP_INT_MIN since PHP 7.0.0.

Windows => 32 bit. It is fixed now, but your code is just wrong. But thanks for note about the error.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Studio 42

i get reported  $mLimit = 2147483648
So 2147483648<5242880 is right.
I checked before sending the fix.
If PHP cannot handle 2147483648 as int, then no one can use it.
Check my solution, if it not work, then your do not work better, i don't understand  why "your code is wrong" ?

Milbo

lol, I have no time to explain you now the INT, I sent already the manual. Your code does not work as the function is meant.

Quote from: Studio 42 on February 16, 2017, 18:24:02 PM

in config.php replace :
static function getMemoryLimitBytes(){
...
$mLimit = (int) $mLimit - 5242880; // 5 MB reserve
if($mLimit<=0){
$mLimit = 1;
$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);
}
The function should return the available memory. We need 5 MB at least for joomla. So when less than 5 MB is set => throw the warning. And set the return to 1 (1 Byte), just to not return 0 (which can be interpreted as false, you know), ELSE return the set memory limit -5MB


Quote from: Studio 42 on February 16, 2017, 18:24:02 PM

if($mLimit<=0) $mLimit = 2147483648;


This just return 2 GB in case someone set as php memory_limit 0, because 0 is "unlimited", which is usually not more than 2 GB

with :

Quote from: Studio 42 link=topic=136707.msg477950

if($mLimit<5242880){
$mLimit = 1;

$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);
}

Sets the returned memory limit to 1 in case less than 5 MB is set. BUT it does NOT reduce the returned memory limit by 5 MB !

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

Studio 42

Max, recheck the code.
I really don't understand the problem, PHP return right INT, but casting the operation give bad result.
IF you need to check for memory limit = 0 , add the condition and it work for this case too.

Milbo

lol, useless.

Your code " BUT it does NOT reduce the returned memory limit by 5 MB !"

The solution is to write instead of this $mLimit = (int) $mLimit - 5242880; // 5 MB reserve

just this $mLimit = $mLimit - 5242880; // 5 MB reserve
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/