I am trying to determine the best way to have a PHP script determine which server the script / site is running on.
I currently have switch()one that uses $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT']to determine which server it is on. Then it sets several paths, db connection parameters, SMTP parameters and debugging parameters, on the basis of which it is enabled. (Perhaps additional options depend on the needs of the site.)
This means that I can simply delete the site on any of the configured servers without the need to change any code (in particular, the configuration). If this is a new server, I just add a new one caseand it is ready from now on.
We downloaded the configuration files based on the same combination SERVER_NAME:SERVER_PORT, but found that this is another file that you need to support, plus we were not sure about the speed of parsing ini files (although there are additional cases for each server, it can be just as slow )
Another problem is that the site is often moved between two servers, but we use the same SERVER_NAME, and SERVER_PORTfor everyone. This means that we need to temporarily comment on one case and make sure that it does not fall into the repo.
Other ideas? It should be available on all servers (sometimes SERVER_NAMEand SERVER_PORTnot). It would be nice if it worked with CLI PHP.
source
share