PHP 中的事件监听器

发布于 2024-09-05 12:51:00 字数 133 浏览 3 评论 0原文

当 PHP 页面已通过套接字成功连接到的另一个 TCP 服务器上发生事件时,我希望我的 Web 服务器通过 PHP 页面通知我。该事件就像 TCP 服务器想要向 Web 服务器发送消息等。是否有任何方法可以完成此操作和/或有关如何执行此操作的任何参考?

I want my web server to notify me through a php page when an event occurs at another TCP server, to which the PHP page has successfully connected via a socket. The event is like the TCP server wants to send a message to the web server, etc. Is there any way to accomplish this and/or any references on how to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以心动 2024-09-12 12:51:00

当然:

$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
        }
    }
}

Sure:

$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
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文