2

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?
Michael Arenzon
  • 541
  • 8
  • 16
  • 1
    Although not an answer to your question: irssi is a great command line irc client. – jli Jul 22 '12 at 20:28
  • I know irssi. I'm not doing the project only because I couldn't find any normal client, its more because I want to learn more about using PHP for cli applications, like clients and etc. – Michael Arenzon Jul 22 '12 at 20:30
  • 1
    Yeah that's cool, just your first sentence suggests that you're looking for an client. – jli Jul 22 '12 at 20:32

1 Answers1

0

try: stream_set_blocking($handle,0)

Threads are not supported in php only forking but that uses up more resources and requires os support (Windows does not support it).

If you want to use a php and threads you could look into phlanger - which is a php (re)implementation for .net (so you need .net or mono on the target platform).

Florian F
  • 4,044
  • 3
  • 30
  • 31