Re: cannot use Net_Ping 2.4

From: Date: Tue, 16 Mar 2004 15:08:06 +0000
Subject: Re: cannot use Net_Ping 2.4
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-11323@lists.php.net to get a copy of this message
to all at pear-general: sorry for top-post and long email ... but otherwise the context is imho lost / to hard to figure out. This has started as a private email ... imho a bad idea! pear-general is the way to go! Hi Felipe, you didn't read my last email carefully, about the result-object :-)) Try this: require_once "Net/Ping.php"; $ping = Net_Ping::factory(); if(PEAR::isError($ping)) { echo "deu erro no ping para o ip $ip"; echo $ping->getMessage(); } else { $ping->setArgs(array('count' => 3, 'timeout' => 1)); $result = $ping->ping("$ip"); $roundTrip = $result->getRoundTrip(); echo is_null($roundTrip['avg']) ? "not okay" : "okay"; } Inspect the source of Ping.php a bit more to see what the returned result-object offers. PS: Next time please better post to pear-general, so everybody can help you and you can also help the others. Please understand that I can't be a personal guide to everyone ... no time, sorry! :-(( Regards, Stefan On 16 Mar 2004 at 11:54, Felipe Ceglia wrote: > Sorry to be bothering you. But I got quite confused, as everything it > returns comes prefixed by an underline. :) > Anyway, how could I simply check if the given host has answered to my ping? > I tried: > > require_once "Net/Ping.php"; > $ping = Net_Ping::factory(); > if(PEAR::isError($ping)) { > echo "deu erro no ping para o ip $ip"; > echo $ping->getMessage(); > } else { > $ping->setArgs(array('count' => 3, 'timeout' => 1)); > if($ping->ping("$ip")){ > print "OK"; > } else { > echo "BUM!"; > }; > } > > Thank you a lot, > > Felipe > > > > > >Well, you're already doing everything correct. Have a look what > >var_dump does: http://www.php.net/var_dump > >It dumps the contents of a variable. So the line: > > > >var_dump($ping->ping('example.com')); > > > >could more clearly be > > > >$resultObj = $ping->ping('example.com'); > >var_dump($resultObj); > > > >You got it? All information is already returned in an object. Other > >functions will normally return an array ... but ping returns an > >object. If you wish to access object-variables directly, you can e.g. > >use $resultObj->_round_trip. The output returned by var_dump help you > >see which fields the an array contains. But you shouldn't access data > >in objects directly if possible otherwise. Use any function provided > >by that object to return the desired data. > > > >PS: All variables / arrays / functions with an underscore as prefix > >are meant to be private and you should try to avoid using them ... > >they might be gone in a next release without notice or contain > >different data - they are not public, normally. > > > >See the docs if there are methods in the object to access the data. > >Here use $resultObj->getRoundTrip() to return the round-trip- > >information.

« previous php.pear.general (#11323) next »