Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Server Name from Command Line

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.

like image 692
Justin Noel Avatar asked Mar 09 '09 14:03

Justin Noel


People also ask

How can I know my server name in PHP?

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.

What is PHP CLI 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.

What is $_ server [' Script_name ']?

$_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.


1 Answers

echo php_uname("n"); 

see http://php.net/manual/en/function.php-uname.php

like image 117
Uwe Mesecke Avatar answered Oct 04 '22 10:10

Uwe Mesecke