【问题标题】:tcp message incompletetcp 消息不完整
【发布时间】:2011-04-30 11:36:03
【问题描述】:

我正在使用 html5 websockets、dev.w3.org/html5/websockets/ 和 php 套接字函数 php.net/manual/en/ref.sockets.php。我的问题是使用 websockets 从客户端发送到服务器的消息被截断为最大 1449 字节。当我将 net.ipv4.tcp_timestamps 设置为 0 时,会收到几个额外的字节。我正在使用socket_recv。我确实尝试循环 socket_recv,但是在第一次调用 socket_recv 之后,会发出以下警告:

Warning: socket_recv(): unable to read from socket [11]: Resource temporarily unavailable in [file] on line 94

注意:

  • 当我使用带有 MSG_DONTWAIT 的 socket_recv() 时,我收到上述警告。例如socket_recv($socket, $data, 10024, MSG_DONTWAIT)
  • 如果我只使用 0,系统会阻塞。例如socket_recv($socket, $data, 10024, 0)

那么,为什么发送的消息会被截断?

我的 sysctl.conf:

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
net.ipv4.tcp_syncookies = 1
net.core.somaxconn = 900
net.ipv4.tcp_fin_timeout = 20
net.core.netdev_max_backlog = 2500


net.core.rmem_default = 262144
net.core.wmem_default = 262144

net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

net.ipv4.udp_rmem_min = 16384
net.ipv4.udp_wmem_min = 16384

net.ipv4.tcp_rmem = 8192 87380 16777216
net.ipv4.tcp_wmem = 8192 65536 16777216

net.ipv4.tcp_mem = 8388608 12582912 16777216
net.ipv4.udp_mem = 8388608 12582912 16777216

net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1 
net.ipv4.tcp_window_scaling = 1

【问题讨论】:

    标签: php linux tcp centos


    【解决方案1】:

    好吧,事实证明我必须在给定套接字的每个 socket_recv() 之后再次调用 socket_select()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-13
      • 2016-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多