Jump to content

Cron job triggers error notice in ProcessWire.php


Robin S
 Share

Recommended Posts

I have a PHP file that bootstraps PW and I'm calling it from a cron job. When the cron fires the script does run but I also get the following error notice:

[01-May-2017 13:07:01 Pacific/Auckland] PHP Notice:  Undefined index: argc in /home/myaccount/public_html/wire/core/ProcessWire.php on line 260

I've seen this reply to a similar problem...

...but I'm not sure that applies in my case. My site is on a shared host and I get the error when I call my cron job like this...

php -q /home/myaccount/public_html/tm_import.php

...which is the recommended format according to my host's documentation. I tried this...

/usr/bin/php -q /home/myaccount/public_html/tm_import.php

...and I get the same notice. Whereas based on @BitPoet's suggestion when I try...

/usr/bin/php-cli -q /home/myaccount/public_html/tm_import.php

...my script doesn't run.

Incidentally, line 260 of ProcessWire.php checks if

php_sapi_name() == 'cli'

and in my case php_sapi_name() is 'cgi-fcgi'. So I'm wondering if PW should be checking for some other variants of php_sapi_name() and I should file a GitHub issue for this, or if I'm just doing something wrong in my cron job.

PHP 7.0, PW 3.0.55

  • Like 2
Link to comment
Share on other sites

3 hours ago, Robin S said:

So I'm wondering if PW should be checking for some other variants of php_sapi_name() and I should file a GitHub issue for this

I would say yes since php_sapi_name()  will return 'cgi' or 'cgi-fcgi' even if cgi is called from the command line.

Some other remarks:

  • The content of $_SERVER differs depending on the call of php-cgi (server or command line)
  • If register_argc_argv is disabled (php.ini) $_SERVER[argc] is not set. Could be checked with ini_get('register_argc_arg');

As far I can see the setting of $config->cli has not an effect inside PW.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...