skip to Main Content

I have a single code base which I am deploying to multiple servers.

I need to identify which server the code is running on in order to use the correct configuration information for the database and so on.

I initially tried using the DOCUMENT_ROOT and checking for the account name.

if (strpos($_SERVER['DOCUMENT_ROOT'], '/var/www/vhosts/SOMETHING.com/') !== false)
{ //is a specific server }

This works well, however I discovered that when my cron jobs are executed DOCUMENT_ROOT is empty, when initiated from Plesk.

Does a better way exist to identify the server?

I do not wish to have a server specific configuration file because the FTP sync software which ensures all files are the same across all servers does not support excluding some files.

Plus, the servers may be running different control panels and setups, so I wish something as general as possible.

2

Answers


  1. Chosen as BEST ANSWER

    I found $_SERVER['HOME'] via cron is the same as DOCUMENT_ROOT.

    This works the same on plesk and cpanel implementations of cron.

    I believe this is better than passing the parameter via the cron command because I would still need to test for it, and also would have to set cron per server, rather that handling this inside the script.


  2. You can pass server name as a command line argument when setting up the cron job.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search