0

I have a socket error when running the socket_recv inside this function:

function readByteXByteSIBmsg() {
    $msg = "";
    $buf="";
    try {
     while( $ret=socket_recv($this->kpSocket,$buf,8192,0)){
        $msg.=$buf;
        if($ret<8192) break;
     }


    $this->deb_print("KpCore:readByteXByteSIBmsg:READ LOOP TERMINATED");
    } catch (Exception $e) {
        err_print("KPICore:readByteXByteSIBmsg:Exception on EVENT  HANDLER:RECEIVE:\n" . $e);
        $this->$KP_ERROR_ID = $this->ERR_SOCKET_TIMEOUT;
    }
    return $msg;
}

This is the text of the error:

PHP Warning:  socket_recv(): unable to read from socket [11]: Resource temporarily unavailable in /home/luca/Documenti/Tesi/M3 Agent Page/lib/KPICore.php on line 236

(line 236 is the line with the socket_recv call)

1 Answer 1

1

The error is EAGAIN (or EWOULDBLOCK, sometimes those are the same error) and means that the socket is non-blocking and that there is nothing to read at the moment. You can busy-wait while you have that error until you read something, or you use some other method to find out if there is data to read before trying to receive.

Sign up to request clarification or add additional context in comments.

3 Comments

Been a few years, but I'm curious. How exactly might I go about using "some other method to find out if there is data to read"?
@i336_ select comes to mind. :)
D'oh. Of course. Yeah, I didn't fully grasp the "oh if you get EAGAIN you just fall back into select() and let it tell you" thing initially... heh. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.