I recently had an issue where my cron events weren’t firing, and after enabling email output, I ended up with something like this PHP error message:
Parse error: syntax error, unexpected '?' in /path/to/file.php on line 123
It turns out that WP-CLI was running PHP 5.x via the DreamHost cron system. I had PHP 7.x specific code in my theme.
To fix this, I had to set the
WP_CLI_PHP environment variable in my cron job:
export WP_CLI_PHP=/usr/local/php72/bin/php wp cron event run --due-now --path=/home/path/to/wp/ --url=https://example.com/