PHP socket cannot process data streams. how to avoid (as if it is blocked) _ PHP Tutorial

Source: Internet
Author: User
Phpsocket cannot process data streams. how to avoid it (as if it is blocked ). Phpsocket cannot process data streams. how to avoid (as if it is blocked) phpsocket cannot process data streams and how to handle (as if it is blocked) needs: php cannot process data streams from a hardware to 8 php socket. how can this problem be avoided (as if it is blocked)
Php socket cannot process data streams. how can this problem be solved (it seems to be blocked)
Requirement: php accepts a hardware to send data to port 8888, the socket_send function should return "\ xFA \ x01 \ x01 \ xFF \ xAA \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ x01 ", after the hardware receives the data sent by socket_send, it will "drip", but the problem arises. one hardware is fine, but when multiple hardware are connected and data is sent at the same time, the hardware will not respond continuously (that is, the sound of a "drop"). That is to say, after a "drop" sound can be sent continuously, it will not sound. after about a few seconds, I started to respond again. after a while, I won't be able to do it again. I have used the non-blocking mode for a few hardware connections. I still want to solve this problem. I will post the code below.

PHP code
   = $ MAX_USERS) {$ reject = "Server full. try again later. \ n ";}// set the current client connection to socket_select and select $ connections [$ I] = $ newconn; // enter the connection resource cache container $ writefds [$ I] = $ newconn; // The connection is abnormal if ($ reject) {$ close [$ I] = true ;} else {echo "Welcome to the PHP Chat Server! \ N ";}// initialize the cache container for the content read by the current connection $ input [$ I] =" "; continue ;}// client connection $ I = (int) $ rfd; // read $ tmp = @ socket_read ($ rfd, 14, PHP_NORMAL_READ); if (! $ Tmp) {// The content cannot be read. print "connection closed on socket $ I \ n"; close ($ I); continue;} $ input [$ I]. = $ tmp; $ tmp = substr ($ input [$ I],-1);/* if ($ tmp! = "\ R" & $ tmp! = "\ N") {// no end of line, more data coming continue;} */$ line = trim ($ input [$ I]); $ input [$ I] = ""; echo 'Client> '. $ line. "\ r \ n"; socket_getpeername ($ connections [$ I], & $ remoteIP, & $ remotePort); echo $ remoteIP. "\ r \ n"; echo $ remotePort. "\ r \ n"; // $ data = str_split ($ buffer); // print_r ($ data ); $ str = "\ xFA \ x01 \ x01 \ xFF \ xAA \ x00 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ x01 "; socket_send ($ connections [$ I], $ str, strlen ($ str), 0 );} Foreach ($ writefds as $ wfd) {$ I = (int) $ wfd; $ w = socket_write ($ wfd, "hello ");}}} function close ($ I) {global $ connections, $ input, $ close; socket_shutdown ($ connections [$ I]); socket_close ($ connections [$ I]); unset ($ connections [$ I]); unset ($ input [$ I]); unset ($ close [$ I]);}?>

Http://www.bkjia.com/PHPjc/1023580.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1023580.htmlTechArticlephp socket processing can not come to the data flow, how to avoid (it seems to be blocked) php socket processing can not come to the data flow, how to deal with (it seems to be blocked) demand: php accepts a hardware program to 8...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.