PHP中的事件侦听器

PHP中的事件侦听器,php,events,webserver,tcpserver,Php,Events,Webserver,Tcpserver,我希望我的web服务器在另一个TCP服务器上发生事件时通过php页面通知我,php页面已通过套接字成功连接到该服务器。该事件类似于TCP服务器希望向web服务器发送消息等。是否有任何方法来完成此操作和/或如何执行此操作的任何参考?确定: $fp = fsockopen("tcp://example.com", 8888) OR die("could not connect"); while (!feof($fp)) { $pc = fread($handle, 8192); if

我希望我的web服务器在另一个TCP服务器上发生事件时通过php页面通知我,php页面已通过套接字成功连接到该服务器。该事件类似于TCP服务器希望向web服务器发送消息等。是否有任何方法来完成此操作和/或如何执行此操作的任何参考?

确定:

$fp = fsockopen("tcp://example.com", 8888) OR die("could not connect");
while (!feof($fp)) {
    $pc = fread($handle, 8192);
    if ($pc === false || strlen($pc) == 0)
        break;
    //a new packet has arrived
    //you should collect the read in a variable and wait
    //for another packet until you know the message is complete
    //(depends on the protocol)
    collect_in_result($pc);
    if (message_is_complete()) {
        if (check_event()) {
            //take action
        }
    }
}

感谢您的回复,请您解释一下代码中发生了什么?请参阅fsockopen和fread(和)的手册条目。我已经修复了一个错误,
fsockopen
必须用来代替
fopen