Wvs
Wvs

Reputation: 45

Creating scheduled tasks in plesk result in error

When creating a scheduled task to run a php script in Plesk Onyx on windows it results in an error.

However when i run the same script in the browser it works without any issues.

I have been looking for the permission settings in the webroot and set them to allow access to all user groups on the server.

The error i get is the following:

Warning: require(\pcp2\inc\db_config.php): failed to open stream: No such file or directory in D:\www\domain\pcp2\conversion\addBooking.php on line 5

Fatal error: require(): Failed opening required '\pcp2\inc\db_config.php' (include_path='.;.\includes;.\pear') in D:\www\domain\pcp2\conversion\addBooking.php on line 5

Line 5 contains the following info:

require($_SERVER['DOCUMENT_ROOT']."\pcp2\inc\db_config.php");

Upvotes: 0

Views: 227

Answers (1)

Alex Howansky
Alex Howansky

Reputation: 53581

It's failing becasue $_SERVER['DOCUMENT_ROOT'] is a value provided by the web server, and is thus undefined when run without a web server (i.e., from the command line.) You'll need to provide an alternative mechanism to set the base directory.

You might use relative paths:

require("pcp2\inc\db_config.php");

Or absolute paths based on the magic constant __DIR__. (This assumes the script doing the require'ing is in the document root directory.)

require(__DIR__."\pcp2\inc\db_config.php");

Ideally however, you're better off using PSR-4 namespacing with an autoloader.

Upvotes: 1

Related Questions