Search code examples
phplinuxcronscheduled-tasksplesk

php script require() statement fetches file when running from browser but not when running from Plesk CRON job


I have a task script that works perfectly fine if i run it by visiting the php file from my browsers. However, when i attempt to run it via Plesk Task Scheduler it fail with a fatal error unable to load the require() file.

The require statement is a simple relative path:

require('../../../app.config.php');

the error is:

PHP Fatal error: require(): Failed opening required '../../../app.config.php'

I think this may be related to the include_path but i don't know much about it so a bit lost on that one.

Any help would be great!


Solution

  • relative pathes resolved by current directory. Solutions: Get script directory and combine with the relative path, something like:

     require(dirname(__FILE__).'/../../../app.config.php');