PHP异步读取(shell脚本)

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?).

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

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

Try stream_set_blocking(), it should do the trick.