我对套接字的 fwrite 不会刷新,直到套接字关闭.如何改变? [英] My fwrite to a socket is not flushed, until the socket closes. How to change?

查看:70
本文介绍了我对套接字的 fwrite 不会刷新,直到套接字关闭.如何改变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对套接字的 fwrite 不会刷新,直到套接字关闭.如何改变?我希望它在每次 fwrite 后刷新.

My fwrite to a socket is not flushed, until the socket closes. How to change? I want it to flush after each fwrite.

我试过了:

1) 冲洗()
2) fflush()
3) ob_implicit_flush(true);

1) flush()
2) fflush()
3) ob_implicit_flush(true);

这些都没有用,我仍然需要退出 php 才能让我的套接字接收数据.

None of those worked, I still had to quit php for my socket to receive the data.

包括一些示例代码,看起来有什么不对吗?

Including some sample code, anything looks wrong?

while($clientSocket = socket_accept($this->serviceConnection))
    {                              
        while( $clientMessage = socket_read($clientSocket, 1024)     )                     
        {                  
            echo 'Relaying message to server: ' . $clientMessage;
            if( !fwrite($this->Connection, $clientMessage) )
                echo 'Error writing to server'; 
            fflush($this->Connection);
        }
        socket_close($clientSocket);
    }

推荐答案

有一个功能可以解决这个问题!fflush($rc)

There is a function for that! fflush($rc)

你确定你有正确的资源作为参数吗?

Did you make sure you had the correct resource as the parameter?

编辑

好的.查看您正在使用 socket_* 函数的代码.您需要使用 fsockopen、fwrite、fflush、fsockclose.您的代码应该工作相同,但您将能够刷新输出.查看示例在php手册中了解更多详情.

Okay. looking at your code you are using socket_* functions. You need to use fsockopen, fwrite, fflush, fsockclose. Your code should work the same, but you will be able to flush output. check out the example in the php manual for more details.

这篇关于我对套接字的 fwrite 不会刷新,直到套接字关闭.如何改变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆