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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog