Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Cron Job Out Of Memory Rate Topic   - - - - -

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11398 posts

Posted 31 May 2019 - 10:06 PM #1

I have a cron script that sets up like the following, but the init.php never returns and there are 2 errors about running out of memory (256MB).

printf("Executing ".__FILE__."\n");
define('AREA', 'A');
define('AREA_NAME', 'admin');
define('ACCOUNT_TYPE', 'admin');
define('NO_SESSION', true);
 
$addon_dir = "/app/addons/ez_shopify";
$cur_dir = getcwd();
if( strpos($cur_dir, $addon_dir) ) {
        // Seems some php installations chdir to the directory of this file
        chdir("../../..");
}
 
printf("Current directory is: %s\n", getcwd());
 
// And to get around bad usage of SCRIPT_FILENAME in the seo addon
if( empty($_SERVER['SCRIPT_FILENAME']) )
    $_SERVER['SCRIPT_FILENAME'] = __FILE__;
// Various unprotected warnings from fn_*() functions.
if(empty($_SERVER['REQUEST_METHOD'])) $_SERVER['REQUEST_METHOD'] = 'GET';
if(empty($_SERVER['REMOTE_ADDR'])) $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
 
printf("Set _SERVER variables, call init.php\n");
 
require_once("./init.php");
use Tygh\Registry;
use Tygh\Mailer;
if( !defined('CONSOLE') )
        define('CONSOLE', true);
ini_set('dipsplay_errors', true);
error_reporting(E_ALL);
 
printf("Init done.\n");

I get to the "Set _SERVER variables, call init.php\n" but the require_once("./init.php") just hangs for nearly a minute and then the error log contains:

# tail error_log
[31-May-2019 17:29:37 America/New_York] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /home/XXXX/public_html/app/Tygh/Database/Connection.php on line 446
[31-May-2019 17:29:37 America/New_York] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /home/XXXX/public_html/app/Tygh/Registry.php on line 440

I tried to add a define('CONSOLE',true) early in the script but it then says it's already defined in Bootstrap.php.

 

I can't figure out what it's trying to do.  I've also tried the more traditional approach of:

php /home/XXXX/public_html/adminpanelname.php --dispatch=addon_name.cron --cron_password=the_cron_password

Where I added a 'mode' to the addon controller called 'cron' which is supposed to call the function but it never gets there.  I tried running other cron jobs that have been setup for other addons on the system and they all die with "exceeded memory limit" errors.

 

I can run ?dispatch=\addon_name.cron just fine from the URL, but not from a command line or cron.

 

Any thoughts?

 


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • kogi
  • Senior Member
  • Members
  • Join Date: 16-Aug 07
  • 620 posts

Posted 01 June 2019 - 06:34 AM #2

You can try adding php "-d memory_limit=-1"  to remove the memory limit while using cli


find / -type f -name '*.base' -exec chown kogi.kogi {} \;

 
  • soft-solid
  • Junior Member
  • Members
  • Join Date: 19-Apr 10
  • 898 posts

Posted 01 June 2019 - 06:03 PM #3

Hello

 

You can add at the beginning of the script

 

@ini_set('memory_limit', '1024M');

 

Best regards

Robert


Team of SoftSolid
cs-cart.pl

 
  • poppedweb
  • Authorized Reseller
  • Members
  • Join Date: 02-Aug 16
  • 549 posts

Posted 02 June 2019 - 11:05 AM #4

I have a cron script that sets up like the following, but the init.php never returns and there are 2 errors about running out of memory (256MB).

printf("Executing ".__FILE__."\n");
define('AREA', 'A');
define('AREA_NAME', 'admin');
define('ACCOUNT_TYPE', 'admin');
define('NO_SESSION', true);
 
$addon_dir = "/app/addons/ez_shopify";
$cur_dir = getcwd();
if( strpos($cur_dir, $addon_dir) ) {
        // Seems some php installations chdir to the directory of this file
        chdir("../../..");
}
 
printf("Current directory is: %s\n", getcwd());
 
// And to get around bad usage of SCRIPT_FILENAME in the seo addon
if( empty($_SERVER['SCRIPT_FILENAME']) )
    $_SERVER['SCRIPT_FILENAME'] = __FILE__;
// Various unprotected warnings from fn_*() functions.
if(empty($_SERVER['REQUEST_METHOD'])) $_SERVER['REQUEST_METHOD'] = 'GET';
if(empty($_SERVER['REMOTE_ADDR'])) $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
 
printf("Set _SERVER variables, call init.php\n");
 
require_once("./init.php");
use Tygh\Registry;
use Tygh\Mailer;
if( !defined('CONSOLE') )
        define('CONSOLE', true);
ini_set('dipsplay_errors', true);
error_reporting(E_ALL);
 
printf("Init done.\n");

I get to the "Set _SERVER variables, call init.php\n" but the require_once("./init.php") just hangs for nearly a minute and then the error log contains:

# tail error_log
[31-May-2019 17:29:37 America/New_York] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /home/XXXX/public_html/app/Tygh/Database/Connection.php on line 446
[31-May-2019 17:29:37 America/New_York] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /home/XXXX/public_html/app/Tygh/Registry.php on line 440

I tried to add a define('CONSOLE',true) early in the script but it then says it's already defined in Bootstrap.php.

 

I can't figure out what it's trying to do.  I've also tried the more traditional approach of:

php /home/XXXX/public_html/adminpanelname.php --dispatch=addon_name.cron --cron_password=the_cron_password

Where I added a 'mode' to the addon controller called 'cron' which is supposed to call the function but it never gets there.  I tried running other cron jobs that have been setup for other addons on the system and they all die with "exceeded memory limit" errors.

 

I can run ?dispatch=\addon_name.cron just fine from the URL, but not from a command line or cron.

 

Any thoughts?

 

As what user are you executing it from the CLI? As your webserver user? (sudo -u [user] php ......)


PoppedWeb | sales@poppedweb.com | https://poppedweb.com
TurnKey Website Design | Add-Ons | Performance Audits | Dedicated Server Management
24/7 Support | Response within an hour (during working hours).

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11398 posts

Posted 03 June 2019 - 03:02 PM #5

I added

error_reporting(E_ALL);
ini_set('display_errors', true);

At the beginning of the script.  But there's no way/reason why initializing cs-cart would take more than 256MB of memory.

And there's nothing in the logs other than PHP error_log showing it trying to use more than 256MB of memory.

 

As what user are you executing it from the CLI? As your webserver user? (sudo -u [user] php ......)

Same user as cs-cart.  I.e. the cpanel user.  Other cron-jobs (from other vendors for other addons) are also failing in the same way.

Otherwise the site runs fine and is pretty fast.

 

tony


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • The Tool
  • Been Here Way Too Long Member
  • Members
  • Join Date: 30-Mar 07
  • 3843 posts

Posted 03 June 2019 - 03:27 PM #6

Just a guess but try using the path to php.

/usr/local/bin/php

or

/usr/local/bin/ea-phpxx


 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11398 posts

Posted 03 June 2019 - 04:07 PM #7

Thanks, we've created a ticket with the hosting.  My guess is that 'php' is tied to a much lower version of php on this server.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.