Question

Output from php script run by cronjob differs from manually executing it

I am getting a different result from a php script when I run it as a cronjob as when I execute it manually. Have tried to look for information but can’t figure out what is happening. Please help!

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @fabriziocastrob6,

It is quite possible that when you run the PHP script via cron it might use a different php.ini file.

I could suggest 2 things:

  • In your crontab make sure to specify the exact path to the php binary, to find out the path run:
  1. which php
  • If the script is in a specific directory, you could add a cd command before the php command in cronjob, so it would look something like this:
cd /path/to/your/directory && /usr/bin/php script.php
  • If this still does not work, try specifying the path to your custom php.ini file if you use one, you can do that by adding the following flag:
php -c /path/to/your/custom/php.ini

Let me know how it goes! Regards, Bobby