• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

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