←Guybrush→ 0 Newbie Poster

Ahoy Sailors!

So I've been racking my brain lately trying to figure out how to serve multiple connections via sockets in PHP. For example so far if two Child scripts connect to my Parent script, The Parent will only start communicating with the earliest connected Child script, Which of course is not very good.

How can I fix this?

$host = "127.0.0.1";
$port = 404;
set_time_limit(0);
// Misc data
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
$result = socket_bind($socket, $host, $port);
$result = socket_listen($socket, 3);
// Networking area, All to do with sockets!
$spawn = socket_accept($socket);
$check = "/";
////////////////////////////////////////////////////////////
while (True){
echo "What would you like to send?\n";
$out = fread(STDIN, 80);

if ($check!=$out){
   socket_write($spawn, $out, strlen ($out));
   echo "Sent\n";
   $check = $out;
                   }
sleep('5');
}
?>

I did do some googling & found one script claiming to do such, However had numerous errors. Can anyone shed some light unto this?

Thanks Bye!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.