FastSitePHP\Net\Config

Network Configuration Info for your Server or Environment

Código Fonte

GitHub

Código de Exemplo

Obtenha Informações de Rede e do Servidor

// Crie um Objeto de Configuração de Rede
$config = new \FastSitePHP\Net\Config();

// Obtenha um (fqdn) 'fully-qualified domain name' para o servidor ['servidor.example.com']
$host = $config->fqdn();

// Obtenha o endereço IPv4 da Rede para o computador ou servidor
$ip = $config->networkIp();

// Obtenha uma lista de todos os endereços IPv4 para o computador ou servidor
$ip_list = $config->networkIpList();

// Obtenha um string de texto de informações do servidor utilizando um
// dos seguintes comandos:
// - Linux / Unix = [ip addr] ou [ifconfig]
// - Mac          = [ifconfig]
// - Windows      = [ipconfig]
$info = $config->networkInfo();

// Converte a String de Informações de Rede em um Objeto
$info = $config->parseNetworkInfo($info);

Métodos

fqdn()

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.

Retorna: string | null 'server.example.com'

networkIp()

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 '127.0.0.1' 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()].

Retorna: string | null

networkIpList()

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.

Retorna: 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
           ifconfig

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

Retorna: 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].

Retorna: null | \stdClass