Recently in an application, I use the socket to collect the number of servers online and then update the RRD database, but finally did not show that the predecessor has relevant experience please advise, the boss has been urging AH;
The code is as follows:
$ss = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_set_option($ss,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>3, "usec"=>0 ) ); socket_set_option($ss,SOL_SOCKET,SO_SNDTIMEO,array("sec"=>3, "usec"=>0 ) );//$latencyStart = microtime(true); //延迟开始计时。 if(socket_connect($ss,gethostbyname($tietu_host),$tietu_port))//更新且连接成功 { socket_write($ss,"\xfe\x01"); $data=explode("\x00",mb_convert_encoding(substr(socket_read($ss,1024),9), 'auto', 'UCS-2')); $tietu_players=$data[3]; if(rrd_update($dbname,"N:$tietu_players")==true){ echo"数据更新成功,数据为".$tietu_players; }else{ echo"数据更新失败"; } }
Reply content:
Recently in an application, I use the socket to collect the number of servers online and then update the RRD database, but finally did not show that the predecessor has relevant experience please advise, the boss has been urging AH;
The code is as follows:
$ss = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_set_option($ss,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>3, "usec"=>0 ) ); socket_set_option($ss,SOL_SOCKET,SO_SNDTIMEO,array("sec"=>3, "usec"=>0 ) );//$latencyStart = microtime(true); //延迟开始计时。 if(socket_connect($ss,gethostbyname($tietu_host),$tietu_port))//更新且连接成功 { socket_write($ss,"\xfe\x01"); $data=explode("\x00",mb_convert_encoding(substr(socket_read($ss,1024),9), 'auto', 'UCS-2')); $tietu_players=$data[3]; if(rrd_update($dbname,"N:$tietu_players")==true){ echo"数据更新成功,数据为".$tietu_players; }else{ echo"数据更新失败"; } }