码迷,mamicode.com
首页 > Web开发 > 详细

php socket 学习

时间:2015-05-01 00:29:34      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

 

socket超时设置

ini_set("default_socket_timeout", -1);

 

stream_set_timeout

$fp = fsockopen("www.example.com", 80);
if (!$fp) {
    echo "Unable to open\n";
} else {

    fwrite($fp, "GET / HTTP/1.0\r\n\r\n");
    stream_set_timeout($fp, 2);
    $res = fread($fp, 2000);

    $info = stream_get_meta_data($fp);
    fclose($fp);

    if ($info[‘timed_out‘]) {
        echo ‘Connection timed out!‘;
    } else {
        echo $res;
    }

}

注意:

1、This function doesn‘t work with advanced operations like stream_socket_recvfrom(), use stream_select() with timeout parameter instead. 

 

php socket 学习

标签:

原文地址:http://www.cnblogs.com/siqi/p/4470144.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!