Page 1 of 1

CLI jobs not finished or broken (cron product feeds)

PostPosted: Tue Nov 26, 2019 7:02 pm
by admin
hello, we just discovered an issue which breaks any CLI or mass operations on Virtuemart when it's run in unlimited memory mode via CLI or with memory_limit = -1

virtuemart automatically sets memory limit to 2GB even when a sitemap or other product feed export may need to up to 10GB of ram in special cases on large shops.

to fix this we are adding an automatic fix to OPC installer which updates:

administrator\components\com_virtuemart\helpers\config.php

original function:
Code: Select all
static function getMemoryLimitBytes(){
      static $mLimit;
      if($mLimit===null){
         $mL = ini_get('memory_limit');
         $mLimit = 0;
         if(!empty($mL)){

            if($mL < 0){
               $mLimit = 2;
               $u = 'G';
            } else {
               $u = strtoupper(substr($mL,-1));
               $ord = ord($u);
               //Just numbers
               if (($ord>=48)&&($ord<=57)) {
                  $mLimit = (int)($mL);
               } else {
                  $mLimit = (int)substr($mL,0,-1);
               }
            }

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

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

               if($mTest<=0){
                  $m = 'Increase your php memory limit, which is much 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;
   }



updated to:
Code: Select all
static function getMemoryLimitBytes(){
      static $mLimit;
      if($mLimit===null){
         $mL = ini_get('memory_limit');
         $mLimit = 0;
         if(!empty($mL)){

            if($mL < 0){
               $mLimit = 2;
               $u = 'G';
            } else {
               $u = strtoupper(substr($mL,-1));
               $ord = ord($u);
               //Just numbers
               if (($ord>=48)&&($ord<=57)) {
                  $mLimit = (int)($mL);
               } else {
                  $mLimit = (int)substr($mL,0,-1);
               }
            }

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

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

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

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

      return $mLimit;
   }



which sets the memory limit to 2^64 bytes instead of 2GB.

best regards, stan