tags:

views:

36

answers:

1

I'm trying to build a little command-line IRC client in PHP because I'm getting sick of all those clients having you click through twenty GUI popups/windows to connect to a new server.

Everything is working so far, but I'm stuck with the main loop that sends my input commands/messages to the server and receives the new data from it.

As PHP isn't very multi-task-friendly I have two autonomous PHP scripts running at the same time:

The input reader where I can enter my messages - it stores the current message in a text file. The server listener/writer which receives new data and reads and clears the text file where the input reader stored my current command in.

However fgets() which I use to read new data from the server pauses the script waiting until something new arrives. So the input text file can't be read out until something new arrives from the server, which is not good.

  • Is there some special function/option to help me out?
+2  A: 

You need to look at streams, and especially stream_set_blocking.

EDIT: in fact, you can get rid of having two processes and do everything in one process. Use non-blocking reads and you should be fine.

janmoesen