資源簡(jiǎn)介
需開(kāi)啟php擴(kuò)展 php_sockets
代碼片段和文件信息
error_reporting(E_ALL?^?E_NOTICE);
ob_implicit_flush();
?
$sk=new?Sock(‘127.0.0.1‘8000);
$sk->run();
class?Sock{
?public?$sockets;
?public?$users;
?public?$master;
??
?private?$sda=array();//已接收的數(shù)據(jù)
?private?$slen=array();//數(shù)據(jù)總長(zhǎng)度
?private?$sjen=array();//接收數(shù)據(jù)的長(zhǎng)度
?private?$ar=array();//加密key
?private?$n=array();
??
?public?function?__construct($address?$port){
?$this->master=$this->WebSocket($address?$port);
?$this->sockets=array($this->master);
?}
??
??
?function?run(){
?while(true){
?$changes=$this->sockets;
?$write=NULL;
?$except=NULL;
?socket_select($changes$write$exceptNULL);
?foreach($changes?as?$sock){
?if($sock==$this->master){
??$client=socket_accept($this->master);
??$key=uniqid();
??$this->sockets[]=$client;
??$this->users[$key]=array(
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件????????6062??2019-12-06?13:10??webserver.php
?????文件????????9681??2019-12-06?13:12??index.html
評(píng)論
共有 條評(píng)論