doushansu9012 2012-06-22 02:44
浏览 192
已采纳

PHP从Socket获取可用字节

So I've been writing this tool and I am using these Sockets (not these) and the difference with them I surmise that the second uses strictly stream-based sockets. The thing is that you can't use socket_get_status on the sockets I am using.

Is there any other way to get the amount of available bytes besides socket_get_status?

  • 写回答

1条回答 默认 最新

  • douzhang5199 2012-06-22 03:36
    关注

    The streams returned from fsockopen() are a managed wrapper around regular sockets; the unread bytes (which is what you're probably after) is the difference between the read() on the socket (made by the wrapper itself) and the fread() on the wrapper (made by your script).

    The wrapper reads in chunks of 8192 bytes, but the fread() or fgets() may not read all data at once, which is why there's an unread meta data field you could query; whether that's useful is another thing ;-)

    When using regular sockets, you could either:

    • use socket_select() to wait for data to become available, followed by a suitably large socket_read()
    • use socket_set_nonblock() to make the socket unblocked and attempt to read from it
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Linux环境下CA证书更新问题
  • ¥60 微信小程序如何上传QQ聊天文件
  • ¥300 开发的系统遭到无良商家的破解,请问如何防止再次发生,并追回损失
  • ¥15 java代码写在记事本上后在cmd上运行时无报错但又没生成文件
  • ¥15 关于#python#的问题:在跑ldsc数据整理的时候一直抱这种错误,要么--out识别不了参数,要么--merge-alleles识别不了参数(操作系统-linux)
  • ¥15 PPOCRLabel
  • ¥15 混合键合键合机对准标识
  • ¥100 现在不懂的是如何将当前的相机中的照片,作为纹理贴图,映射到扫描出的模型上
  • ¥15 魔霸ROG7 pro,win11.息屏后会显示黑屏,如图,如何解决?(关键词-重新启动)
  • ¥15 有没有人知道这是哪里出了问题啊?要怎么改呀?