Cron.php error: PHP Fatal error: Uncaught TypeError

Running with v8.8.0 and php v8.2.x and when executing sudo -u www-data php -f cron.php I get the following error:

PHP Fatal error:  Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, string given in /home/crmsystem/html/public/legacy/cron.php:62
Stack trace:
#0 /home/crmsystem/html/public/legacy/cron.php(62): in_array()
#1 {main}
  thrown in /home/crmsystem/html/public/legacy/cron.php on line 62

were line 62 (and 63) contains:

        if (!in_array($cronUser, $sugar_config['cron']['allowed_cron_users'])) {
            $GLOBALS['log']->fatal("cron.php: running as $cronUser is not allowed in allowed_cron_users ".

Cron user to be used as been set to www-data in SmartCRM config. What is missing to fix this?

Can you post the exact way in which you defined cron_allowed_users in your config.php or config_override.php?

Sure, in config.php line 92 - 97 includes:

  array (
    'max_cron_jobs' => 10,
    'max_cron_runtime' => 30,
    'min_cron_interval' => 30,
    'allowed_cron_users' => 'www-data',
  ),

I believe it should be an array (even if it has only one element), not a single string value.

If you check examples online or the default values, you will see this.

Yes, thanks, thought I fixed it last time but which I didn’t works fine now when trying to run from cli:

  array (
    'max_cron_jobs' => 10,
    'max_cron_runtime' => 30,
    'min_cron_interval' => 30,
    'allowed_cron_users' =>
    array (
      0 => 'www-data',
    ),
  ),

2 Likes