Can't read from socket (hangs)

前端 未结 4 1564
深忆病人
深忆病人 2021-02-06 07:17

I am using PHP to connect to a local C++ socket server to keep state between a web app and a couple of daemons. I can send data to the socket server, but not receive from it; i

4条回答
  •  庸人自扰
    2021-02-06 07:56

    You can also try this when reading from socket:

    if(socket_recv ( $socket , $response , 2048 , MSG_PEEK)!==false)
    {
       echo "Server said: $response";
    }
    

    Note: Using MSG_WAITALL in place of MSG_PEEK might cause socket to hang (from one experience I once had).

提交回复
热议问题