SCRIPT_NAME & SCRIPT_FILENAME errors with cron

CRON Errors
You may encounter those errors in your log while inspecting those:
[23-Oct-2016 20:05:24 UTC] PHP Notice:  Undefined index: SCRIPT_NAME in /home/username/public_html/cron.php on line 39
[23-Oct-2016 20:05:24 UTC] PHP Notice:  Undefined index: SCRIPT_FILENAME in /home/username/public_html/cron.php on line 40

Those errors are fom the framework PHP CRON file.

Why is it happening?
While executing the cron, SCRIPT_NAME and SCRIPT_FILENAME aren't expanded by the system.

Solutions?
It is possible to include environment variables directly from the cron tab.

Global (This approach may naot work on certain OS)
1a) From a terminal, ecit the contab by executing the following command (it must be done from the web server user):
crontab -e

1b) Add the following to the top:
SCRIPT_NAME="cron.php"
SCRIPT_FILENAME="cron.php"

1c) Save and close the editor.


Per cron job (easier and safer to implement)
2) Prepend the following to your cron job:
export SCRIPT_NAME=cron.php; export SCRIPT_FILENAME=cron.php;

Example
*/5 * * * * export SCRIPT_NAME=cron.php; export SCRIPT_FILENAME=cron.php; php ~/public_html/cron.php  >/dev/null 2>&1

The error should now be gone following the crontab update.

  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

Why is Magento cron job not working?

cPanel + CageFS and CloudLinux's PHP switcher may cause problems with Magento CRON. Until this is...

How to add a Contact Us form to a page in Magento

Magento has a default Contact Us page usually located in the footer of the store. This page...

Magento Security Tips

E-commerce Site VulnerabilitiesMost e-commerce platforms and payment gateways possess the same...

How to add a custom link to the top navigation in Magento

By default, Magento's top navigation contains links to your product categories. But what if you...

How to add and edit polls in Magento

Adding and editing polls in Magento is easy. You can do that from the admin panel. Go to...