0

I've updated my crontab using crontab -e to run the Laravel task scheduler every minute. It wasn't working so I set it to add its output to a log file, like so:

* * * * * php /path/to/project/artisan schedule:run >> cron_output.log 

Now the log contains the following message:

Parse error: parse error in /path/to/project/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 233

This is the method it points to (I've commented next to line 233):

function cache()
    {
        $arguments = func_get_args();

    if (empty($arguments)) {
        return app('cache');
    }

    if (is_string($arguments[0])) {
        return app('cache')->get($arguments[0], $arguments[1] ?? null);    //line 233
    }

    if (! is_array($arguments[0])) {
        throw new Exception(
            'When setting a value in the cache, you must pass an array of key / value pairs.'
        );
    }

    if (! isset($arguments[1])) {
        throw new Exception(
            'You must specify an expiration time when setting a value in the cache.'
        );
    }

    return app('cache')->put(key($arguments[0]), reset($arguments[0]), $arguments[1]);
}

I don't understand this issue, as Laravel runs normally otherwise. PHP version is 7.2 (based on php -v and also phpinfo()) so that shouldn't be a problem. Is it possible that somehow the crontab is using an older version of PHP? If so how do I fix this? Any other ideas?

sveti petar
  • 3,637
  • 13
  • 67
  • 144
  • Did you run this job locally? Did it work? Looks like the job uses Cache and whatever you're passing in cannot be parsed. – lesssugar Nov 23 '17 at 11:06
  • I'm not running any particular task, it's just Laravel's deafult 'inspire' task inside the scheduler. And even if I remove that it still has the same error. – sveti petar Nov 23 '17 at 11:09
  • `return app('cache')->get($arguments[0], $arguments[1], null);` – urfusion Nov 23 '17 at 11:09
  • @urfusion That makes sense but surely I shouldn't have to edit the syntax of Laravel core files? – sveti petar Nov 23 '17 at 11:10
  • What is the version of you laravel. Because I have not found cache function in my laravel helper file. – urfusion Nov 23 '17 at 11:14
  • @urfusion 5.5.20 – sveti petar Nov 23 '17 at 11:16
  • @urfusion Also see here: https://laravel.io/forum/laravel-55-syntax-error-unexpected-in-vendorlaravelframeworksrcilluminatefoundationhelpersphp-on-line-233 - but my PHP version is 7.2 so it doesn't make sense. – sveti petar Nov 23 '17 at 11:19
  • https://stackoverflow.com/questions/45992685/php-parse-error-syntax-error-unexpected-in-helpers-php-233 – urfusion Nov 23 '17 at 11:21
  • @urfusion As I said, my PHP version (got in command line) is 7.2. In phpinfo it's also 7.2. In the PhpStorm settings panel, the "CLI interpreter" is 7.2 and the "PHP language level" is 7. So what I really want to know is why crontab is pulling some old version of PHP out of the bag. – sveti petar Nov 23 '17 at 11:30
  • Is your /path/to/project/ correct?? – Sohel0415 Nov 23 '17 at 12:30
  • @Sohel0415 Yes. In the end I resolved it by giving the full PHP path to the cron syntax itself (instead of just "php") but I would still like to know how this problem was possible to begin with. – sveti petar Nov 23 '17 at 13:17
  • @jovan well if it works, congrats. Probably the reason behind your problem was the incorrect path. To execute schedule run, it needed the artisan command file of your actual project directory – Sohel0415 Nov 24 '17 at 15:23

0 Answers0