Network Configuration Info for your Server or Environment

Código Fuente


Código de Ejemplo

Get Network and Server Info

// Create a Networking Config Object
$config = new \FastSitePHP\Net\Config();

// Get a (fqdn) 'fully-qualified domain name' for the server ['']
$host = $config->fqdn();

// Get the Network IPv4 Address for the computer or server
$ip = $config->networkIp();

// Get a list of all IPv4 Addresses for the computer or server
$ip_list = $config->networkIpList();

// Get a text string of info from the server using one of the following commands:
// - Linux / Unix = [ip addr] or [ifconfig]
// - Mac          = [ifconfig]
// - Windows      = [ipconfig]
$info = $config->networkInfo();

// Convert the Network Info String to an Object
$info = $config->parseNetworkInfo($info);



Return a (fqdn) 'fully-qualified domain name' for the server that is running this script. A fqdn might not be available which will result in null being returned. This function performs a DNS lookup on the hostname of the server.

Returns: string | null ''


Return the IPv4 Address of the computer or server that is running the script. This can be used if a site is installed in an environment with multiple web servers to determine what server a specific user is accessing. If a computer is not connected to a network and PHP is running from a development environment then this function will likely return the localhost address '' however if connected to the internet or a corporate network then this function will return the computer's network IP address. To get the IP Address of the Web Server Software see the function [FastSitePHP\Web\Request->serverIp()].

Returns: string | null


Return any array of IPv4 Address of the computer or server that is running the script. Often a server will have more than 1 IP assigned.

Returns: array

networkInfo($all = false)

Return a string of Network Info from the OS. If Network info can't be determined then null will be returned. This function works with various OS's including Windows, Mac, and recent versions of Linux. It runs the following commands:

    Win:   ipconfig
           ipconfig /all    (If the optional [$all] parameter is true)
    Mac:   ifconfig
    Other: ip addr

For Linux newer versions will typically include the [ip] command. For older versions of Linux or Unix OS's [ifconfig] will usually be used.

Returns: null

parseNetworkInfo($config_text, $exception_on_parse_error = false)

Parse Network Info that from the function [networkInfo()] from a string to a PHP Basic Object. By default an error will cause [null] to be returned unless the parameter [$exception_on_parse_error] is set to [true].

Returns: null | \stdClass