Cron Job Out Of Memory

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?

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

Hello

You can add at the beginning of the script

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

Best regards

Robert

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 ......)

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

Just a guess but try using the path to php.

/usr/local/bin/php

or

/usr/local/bin/ea-phpxx

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.