Quick Tip: DreamHost cron and WP-CLI

If you’re hosting your WordPress website on DreamHost, and use their cron system to offload your WordPress faux-cron for better reliability, be careful of what version of PHP you have in your code.

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/Code language: JavaScript (javascript)

Other Posts Not Worth Reading

Hey, You!

Like this kind of garbage? Subscribe for more! I post like once a month or so, unless I found something interesting to write about.


Comments

Leave a Reply