PHP Socket Server

Hello everyone!
So I’ve been building a prototype flash/php chat application. I used the php resources located here…

http://www.kirupa.com/developer/flash8/php5sockets_flash8_4.htm <-- great tutorial, thanks!

I’ve since built alot of functions onto the server side script but have a single remaining perplexing dilemma.

The while loop is only running whenever outside data gets sent to a socket… here is an example of what I am trying to do…

In the portion of the code which in the original tutorial said…


if (($client = socket_accept($master)) < 0) {
echo "socket_accept() failed: reason: " .socket_strerror($msgsock). "
"; 
continue;
} 
else {
array_push($read_sockets,$client);
}

I’ve added something like…


if (($client = socket_accept($master)) < 0) {
echo "socket_accept() failed: reason: " .socket_strerror($msgsock). "
"; 
continue;
} 
else {
$msg= "Look what the n00b brought in... errr... welcome to the server
"; $client_arr[0]=$client;  
send_Message($client_arr, "Server", $msg);
array_push($read_sockets,$client);
}

Now the problem is… it doesn’t send the message right away. It waits until the server has gotten a message from someone and then sends it at that time… (it doesn’t matter who sent the message). Instead of sending the message right away like a good little script!

I’ve found that (like I said previously) the while loop only runs when data gets sent over a socket. Any ideas? I’ve tried all sorts of things… including tricking it into running… it’s a stubborn script and sees right through me. doh!

Your help is much appreciated… I can send the complete script to you if you’d like to look at it closer. Help!
Thanks,
-Dietrich