3

I have a PHP TCP daemon which provides data to clients. One of the features is to get info from "tail -f messages" command. So I have to run this command asynchronously and in case of new data, send it to the clients.

I have a problem how to create this asynchronous reader - when new data is added, run the method, otherwise do the other things you have to.

Mejmo

EDIT: My problem could be resolved by using some kinds of threads and IPC (does php support threads?).

Mejmo
  • 2,363
  • 9
  • 35
  • 54

3 Answers3

1

If you can install extensions, you can implement this using the libevent PHP extension.

Evert
  • 93,428
  • 18
  • 118
  • 189
0

Use popen to execute tail -f message, passing 'r' as the $mode parameter. Then you can fread from the returned file pointer.

Oswald
  • 31,254
  • 3
  • 43
  • 68
-1

Try stream_set_blocking(), it should do the trick.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
weasel5i2
  • 119
  • 1
  • 3