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.
PHP: $_SERVER['SERVER_NAME'] States name of the host server. Following php code used $_SERVER['SERVER_NAME'] variable to display name of the host server.
PHP's Command Line Interface (CLI) allows you to execute PHP scripts when logged in to your server through SSH. ServerPilot installs multiple versions of PHP on your server so there are multiple PHP executables available to run.
$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.
echo php_uname("n");
see http://php.net/manual/en/function.php-uname.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With