Set a timeout on socket_read

前端 未结 4 1897
忘掉有多难
忘掉有多难 2021-01-01 17:08

I was wondering how can I set a timeout on a socket_read call? The first time it calls socket_read, it waits till data is sent, and if no data is s

4条回答
  •  -上瘾入骨i
    2021-01-01 17:49

    $read_socket = socket_select($read, $write  = NULL, $except = NULL, 10); // 10 - Timeout
    if($read_socket === FALSE)
        $this->End();
    elseif($read_socket === 0)
        return FALSE;
    
    $pdu_ = socket_read($this->session, 102400);
    if($read_socket && !strlen($pdu_))
        $this->End();
    

提交回复
热议问题