最近在做一个应用,我使用socket收集服务器的在线人数然后更新rrd数据库,但是最后都没显示出来,有哪位前辈有相关经验请指教,老板一直在催啊;
代码如下:
<code> $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"数据更新失败"; } } </code>
最近在做一个应用,我使用socket收集服务器的在线人数然后更新rrd数据库,但是最后都没显示出来,有哪位前辈有相关经验请指教,老板一直在催啊;
代码如下:
<code> $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"数据更新失败"; } } </code>