niwa3836 Posted November 24, 2008 Share Posted November 24, 2008 Guys, I am trying to write some code that looks for any new attempts to connect to a socket whilst servicing other sockets that may already be open (so many clients can connect and be at various stages of being serviced - like most multithreaded programs do i guess). Below is some code from www.php.net (http://uk.php.net/manual/en/function.socket-accept.php#82618) which is just the beginning of my code (i intend to store newc in an array and if valid then service during the while loop, HOWEVER, the demo program (although runs and preforms -i.e. multiple connections at any 1 time) it throws lots of (and I mean lots!!!!!) into the apache log file (which isnt going to work): - [Mon Nov 24 20:22:48 2008] [error] [client 127.0.0.1] PHP Warning: socket_accept() [<a href='function.socket-accept'>function.socket-accept</a>]: unable to accept incoming connection [0]: A non-blocking socket operation could not be completed immediately.\r\n in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\socketin.php on line 11 [Mon Nov 24 20:22:48 2008] [error] [client 127.0.0.1] PHP Warning: socket_accept() [<a href='function.socket-accept'>function.socket-accept</a>]: unable to accept incoming connection [0]: A non-blocking socket operation could not be completed immediately.\r\n in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\socketin.php on line 11 <?php $clients = array(); $socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); socket_bind($socket,'0.0.0.0',5555); socket_listen($socket); socket_set_nonblock($socket); while(true) { if(($newc = socket_accept($socket)) !== false) { echo "Client $newc has connected\n"; $clients[] = $newc; } } ?> Any ideas? It makes sense to be non blocking i guess as need to continue to loop to service other connections and cant "wait" for new connections!! Quote Link to comment https://forums.phpfreaks.com/topic/134100-multiple-sockets-help-please/ Share on other sites More sharing options...
niwa3836 Posted November 24, 2008 Author Share Posted November 24, 2008 Guys, hold off please, might have been a little eager to ask here. I am looking at http://devzone.zend.com/article/1086-Writing-Socket-Servers-in-PHP which seems really useful Quote Link to comment https://forums.phpfreaks.com/topic/134100-multiple-sockets-help-please/#findComment-698065 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.