I have a website. That is setup like this:
/public_html
index.php
common.php
db.php
/dev
index.php
common.php
db.php
common.php contains recurring functions. Db.php contains the database connection info.
common.php also contains functions to determine weather the page being accessed currently is in ‘Dev’ or ‘Production’. It then uses this info to call up include files accordingly.
The problem is, I also have some Cron Jobs setup, which call Php Scripts located outside public_html. But none of the includes work, because the functions that dtermine that paths, use $_SERVER variables, and rely on pieces of the URL (like the presence of the word ‘/dev’).
So, am I better off just having a separate set of files for my Cron Jobs (database connections and functions) even if they may duplicate the same files in the other parts of the site?
You can use OS environment variables to set the execution environment of your scripts.
Crontab:
Your scripts: