php任务同时,php怎么同时处理多个任务(关于php socket)

PHP code$commonProtocol = getprotobyname("tcp");$socket = socket_create(AF_INET, SOCK_STREAM, $commonProtocol);@socket_bind($socket, '192.168.1.202', 8888);@socket_listen($socket);// Initialize the buffer$buffer = "NO DATA";while(true){sleep(1); // Accept any connections coming in on this socket $connection = @socket_accept($socket); printf("Socket connected\r\n"); // Check to see if there is anything in the buffer if($buffer != "") { printf("Something is in the buffer...sending data...\r\n"); @socket_write($connection, $buffer . "\r\n"); printf("Wrote to socket\r\n"); } else { printf("No Data in the buffer\r\n"); } // Get the input while($data = @socket_read($connection, 14, PHP_NORMAL_READ)) { if (!empty($data)){ $buffer = $data; //文件驱动模式 /*$f = fopen(dirname(__FILE__).'/file/'.date('YmdHis').'.txt','w'); fwrite($f,$buffer); fclose($f); */ socket_set_nonblock($connection); socket_getpeername($connection,&$remoteIP,&$remotePort);echo $remoteIP."\r\n";echo $remotePort."\r\n"; $data=str_split($buffer); print_r($data); foreach($data as $v){ echo dechex(ord($v))."\t"; } echo "\r\n"; } } @socket_close($connection); printf("Closed the socket\r\n\r\n"); }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值