后端开发|PHP问题
php,socket,超时时间
后端开发-PHP问题
webshell箱子源码,vscode中禁止运行脚本,ubuntu 背景颜色,给tomcat窗口命名,食叶爬虫,兄弟连php培训多少钱,山城区seo推广电话lzw
anynote源码,vscode 应用教学,暗影精灵8安装ubuntu,jboss取代tomcat,sqlite如何删除字段,dz3.2上传附件插件,前端框架模块教程交流,网络爬虫软件排名,php 变量字符串,seo多少钱一个月,信息采集系统网站源码,手机下网页视频无法播放视频软件,php留言本模板,jsp登录页面的代码,工单管理系统网页源码,wordpres开源程序lzw
【相关学习推荐:php编程(视频)】
javascript解释器源码,ubuntu16美化,将tomcat安装到服务,爬虫思路大全,装修报价系统 php,怎么做百度收录排名seo教程lzw
php socket设置超时的方法:
php创建socket的方法和设置超时的方法,贴出来分享一下
//如果$waitAckSec=0,则返回成功发送的字节 //如果$waitAckSec大于0,则返回发送后接收到得内容 //任何情况下,失败都返回FALSE function sendUdp($host, $port, $buff,$waitAckSec=0) { $socket = ($result = @socket_create(AF_INET,SOCK_DGRAM,SOL_UDP)); //发送超时1秒 socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,array("sec"=>3, "usec"=>0 ) ); //接收超时6秒 socket_set_option($socket,SOL_SOCKET,SO_SNDTIMEO,array("sec"=>6, "usec"=>0 ) ); if($socket){ $result = @socket_sendto($socket,$buff,strlen($buff),0,$host,$port); if($waitAckSec>0){$result = FALSE;$read = array($socket);$write = NULL;$except = NULL;if(@socket_select($read,$write,$except,$waitAckSec)>0){ $fromHost = ""; $fromPort = 0; @socket_recvfrom($socket,$result,4096,0,$fromHost,$fromPort); $result = phpext_unpack($result); if($result["needAck"] == 1){ $this->sendUdp($host, $port, $result["ackdata"]); if(isset ($result[data][list]) && isset ($result[data][ otalCount])){ $list = $result[data][list]; $count = $result[data][ otalCount]; while($count> count($list)){@socket_recvfrom($socket,$result_temp,4096,0,$fromHost,$fromPort);$result_temp = phpext_unpack($result_temp);$this->sendUdp($host, $port, $result_temp["ackdata"]);$list = array_merge($list,$result_temp[data][list]); } $result[data][list] = $list; } }else{ @socket_recvfrom($socket,$result,4096,0,$fromHost,$fromPort); $result = phpext_unpack($result); if($result["needAck"] == 1){ $this->sendUdp($host, $port, $result["ackdata"]); if(isset ($result[data][ esult]) && isset ($result[data][userID])){$list = $result[data][list];$count = $result[data][ otalCount];while($count> count($list)){ @socket_recvfrom($socket,$result_temp,4096,0,$fromHost,$fromPort); $result_temp = phpext_unpack($result_temp); $this->sendUdp($host, $port, $result_temp["ackdata"]); $list = array_merge($list,$result_temp[data][list]);}$result[data][list] = $list; } } }}else{ $result = SEND_UDP_ERROR;} } @socket_close($socket); } return $result; }