socket - 关于php+rrd绘图问题

WBOY
Release: 2016-06-06 20:44:11
Original
1137 people have browsed it

最近在做一个应用,我使用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>
Copy after login
Copy after login

回复内容:

最近在做一个应用,我使用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>
Copy after login
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template