skip to Main Content

Little help or guidance. Server is CentOS 7 – with WHM/CPanel installed.

Command:

$(which php) $(which wp) core update --require=/opt/wp-cli-pre.php --path=/home/USER/public_html/

The contents of /opt/wp-cli-pre.php

<?php
if(!defined('STDIN')) define('STDIN',  fopen('php://stdin',  'r'));
if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'w'));
if(!defined('STDERR')) define('STDERR', fopen('php://stderr', 'w'));

Works as expected from the command line, but if from cron job, I get:

PHP Warning: Use of undefined constant STDOUT – assumed ‘STDOUT’ (this will throw an Error in a future version of PHP) in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/utils.php on line 1057

output of “which php”
/usr/local/bin/php

output of “which wp”
/usr/local/bin/wp

I have installed the latest WP-CLI from https://wp-cli.org/

2

Answers


  1. Chosen as BEST ANSWER

    At long last, I have found the solution.

    When the CRON runs a PHP script like this: */5 * * * * php /path/to/script.php

    The SAPI name is: cgi-fcgi (on a WHM/CPanel install on CentOS)

    It cannot find the CLI version setup by CPanel at /usr/local/bin/php as the $PATH var is just: /usr/bin:/bin

    So, the solution is to not depend on the system environment to determine the PHP you want. But to set that directly.

    Like this: */5 * * * * /usr/local/bin/php /path/to/script.php

    It was always my assumption that if a CRON was setup in ROOT's crontab, it would inherit ROOT's environment. This apparently is not the case.


Please signup or login to give your own answer.
Back To Top
Search