# PHP Socket Server

**URL:** <https://forum.kirupa.com/t/php-socket-server/250284>\
**Category:** flash\
**Created:** [January 28, 2008, 2:36am UTC](https://forum.kirupa.com/t/php-socket-server/250284 "2008-01-28T02:36:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dietrich](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@dietrich](https://forum.kirupa.com/u/dietrich)\
**Post date:** [January 28, 2008, 2:36am UTC](https://forum.kirupa.com/t/php-socket-server/250284/1 "2008-01-28T02:36:09Z")

</div>

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](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…

```php

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…

```php

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
