[olug] questions about socket programming

Jeff Hinrichs - DM&T jeffh at dundeemt.com
Sat Aug 1 21:28:18 CDT 2020


Not sure what you are trying to accomplish,  but this is a decent tutorial
https://webmobtuts.com/backend-development/introduction-to-php-sockets-programming/
what happens depends on if you socket code is async or not and how you
write it will determine
if that is possible.  The link above shows how to accomplish it in PHP (or
at least says it does.)
I have not tested the code or used PHP in quite some time.  So you milage
may vary or someone with more recent PHP fu
will pipe up.

Good luck with your endeavors
-Jeff
The other thing I was alluding to is web sockets.

On Sat, Aug 1, 2020 at 8:26 PM Lou Duchez <lou at paprikash.com> wrote:

> You folks know your socket programming inside out (I bet), so a couple
> questions about a PHP socket server I've written.
>
> First thing the code does is create a socket (let's call it
> "$greeter_socket") for fielding incoming connections.  Then a grand loop
> happens where I iteratively check for incoming connections on
> $greeter_socket, create sockets for bidirectional communications for
> each incoming connection, and also do all the reads / writes to all the
> bidirectional sockets as needed.  Here are my questions:
>
> 1) What happens if two people are trying to connect at the same time?  I
> imagine that the socket can handle only one connection at a time, so
> $greeter_socket will handle whoever got there first, and the other
> person will have to try again and again until they get through or their
> retry period expires.
>
> 2) The code examples I've seen do not put any sort of sleep(), usleep(),
> or time_nanosleep() in the grand loop. That seems ill-advised to me;
> based on my testing, the grand loop consumes a ton of CPU unless I put a
> brief sleep (maybe one-tenth second) in each iteration.  Am I wrong to
> put the sleep in there?  Am I handling it wrong?
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> https://www.olug.org/mailman/listinfo/olug
>


-- 
Best,

Jeff Hinrichs
402.320.0821


More information about the OLUG mailing list