PHP Classes

error handling improvement suggestion

Recommend this page to a friend!

      Net Ping  >  All threads  >  error handling improvement suggestion  >  (Un) Subscribe thread alerts  
Subject:error handling improvement suggestion
Summary:error handling improvement suggestion
Messages:1
Author:kruvas
Date:2012-02-20 12:28:10
 

  1. error handling improvement suggestion   Reply   Report abuse  
Picture of kruvas kruvas - 2012-02-20 12:28:11
if socket_create disabled, class not died and continue work and show could not connect to ... (if not defined source ip)
or die Couldn't bind socket: permission denied

i suggets add on top of ping function check for socket creating succesfull
function Ping($dst_addr, $src_addr="", $timeout=5, $precision=3) {
// check for socket existance
if ($this->icmp_socket===false)
{
$this->errstr = socket_strerror(socket_last_error());
die("socket_create() failed: reason: " . $this->errstr);
}

also some semantics:
replace constant
$this->icmp_socket = socket_create(AF_INET, SOCK_RAW, 1);
with
$this->icmp_socket = socket_create(AF_INET, SOCK_RAW, getprotobyname('icmp'));

удачи )