User Tools

Site Tools


uphp:functions:ping

ping

WMPRO, WMMINI FW >= 1.0 WMMEGA FW >= 2.0

Send an ICMP ping and place the result in an array

Description

array ping ( string $host )

This function sends an ICMP ping request to a host by name or IP address and returns connection information as an array.

Parameter

$host: A URI web address name (such as example.com) or an IP address (such as 172.16.254.1). If a URI is provided the function will attempt to resolve it to an IP address by DNS.

Return Values

A key/value array of connection status information:

KeyTypeDescription
responseint1 if connection was successful, -1 if failure
timeintResponse time in ms
hoststringHost name or IP address as passed to the function
ipstringIP Address that DNS returned for the host
seqintIncremental sequence number for ping

Example

<?
  $res=ping("example.com");
?>

Sample result if no connection is established:

[$res] = Array (
(int) [response] => -1
(string) [host] => example.com
(string) [ip] => 0.0.0.0
(int) [seq] => 0
) 

Sample result if a connection is successful:

[$res] = Array (
(int) [response] => 1
(int) [time] => 25
(string) [host] => example.com
(string) [ip] => 93.184.216.34
(int) [seq] => 2
) 

See Also

fsockopen() - Open an internet socket connection with optional timeout

uphp/functions/ping.txt · Last modified: 2021/09/13 05:57 (external edit)