• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Issue Job runs from browser but not in cron

brownbag

Basic Pleskian
I have a daily job that I run, written in php, which works fine when run manually from a browser, but fails on the following line when run as a schedulued (cron) job set up in plesk.

The line that has the issue is this:

require '../inc/_global/db_con.php';

The php script is located in /var/www/vhosts/compleit.com/customer/sm/cron

The db_con.php file that it is referencing is located in /var/www/vhosts/compleit.com/customer/sm/inc/_global

The error is attached.

I can get it to work as a cron job by changing the line to the following:

require '/var/www/vhosts/compleit.com/customer/sm/inc/_global/db_con.php';

But I shouldn't need to specify the full path (and don't want to, as I want to use this code for customers other than 'sm'.

How do I get it to work in cron without having to specify the full path?
 

Attachments

  • error-screen.png
    error-screen.png
    86.7 KB · Views: 5
You need to use "magic constants" in PHP to achieve your goal. These are constants that are replaced on runtime with dynamic content, for example __DIR__ with the path to the current script. So you don't need to know the path. See this for more on it:
 
You need to use "magic constants" in PHP to achieve your goal. These are constants that are replaced on runtime with dynamic content, for example __DIR__ with the path to the current script. So you don't need to know the path. See this for more on it:

That does enable me to build the value that I need with dynamic conetnt. The issue now is how to get the require command to work with a variable. I'm not sure if this is possible.
 
Back
Top