Is there a way to detect the name of the server running a PHP script from the command line?
There are numerous ways to do this for PHP accessed via HTTP. But there does not appear to be a way to do this for CLI.
For example:
$_SERVER['SERVER_NAME']
is not available from the command line.
The SERVER_NAME is not available when you run PHP from the CLI for that very same reason.
When you run PHP from the CLI, you start your own PHP intepreter that runs whatever code you passed to it, without any kind of server. So from the CLI, PHP knows nothing about your web server that you do not explicitly tell it.
You can add your php script to command line that will set $_SERVER['SERVER_NAME'] for you. Here is how I'm using it:
router.php
Try: