Re: PHP: how to ping a server ?

From: Date: Tue, 19 Dec 2000 15:35:48 +0000
Subject: Re: PHP: how to ping a server ?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31098@lists.php.net to get a copy of this message
>Hello, > >I'm looking for 3 day's for a PHP code that's pings a server. And i got not yet a succesful code, so maby the The Master's can help. >I want the result's something like thise "www.php.net Ping : 200" > >I hope that The Master's can help me ;) >Greets fron Paul Hello Paul, I have two little scripts which check the status of an http-server. You can do that with org. php-functions below the scripts: function GetUrlViaProxy($proxy, $port, $url) { $buf = ""; $fp = @fsockopen($proxy, $port); if ($fp > 0) { fputs($fp, "HEAD $url HTTP/1.1\n\n"); while (!feof($fp)) { $buf .= fgets($fp, 1024); } fclose($fp); } return $buf; } // function GetUrlViaProxy function GetUrl($link) { // $link = http://www.foo.com/index.html => www.foo.com/index.html $foo = parse_url($link); $host = $foo["host"]; $path = $foo["path"]; $buf = ""; $fp = @fsockopen("$host",80); if ($fp > 0) { fputs($fp, "HEAD $path HTTP/1.1\n\n"); while (!feof($fp)) { $buf .= fgets($fp, 1024); } fclose($fp); } return $buf; } // function GetUrl if you want to check, if a servers ip is alive, make <?PHP $ping = "ping -c 1 -q localhost"; system($ping,$ret); printf("ping successful : %s\n",$ret); ?> in $ret you can find a "0", if the ping was successful, otherwise $ret is "1" (tested on a SuSe linux system) Greetings Juergen ----------------------------- Juergen Kaatz WWE e-commerce IT GmbH Eiffestrasse 462 20537 Hamburg URL: http://www.e-commerceit.de/ URL: http://www.iets.de/ (Internet Export Trading System) kaatz@e-commerceit.de Tel: +49-40-2530659-32 Tel. +49-40-2530659-0 (Zentrale) E-Mail : kaatz@e-commerceit.de

« previous php.general (#31098) next »