jakubkulhan/bunny

ClientException

sm2017 opened this issue · 5 comments

Why I have too many ClientException from the following lines?

https://github.com/jakubkulhan/bunny/blob/master/src/Bunny/AbstractClient.php#L302
https://github.com/jakubkulhan/bunny/blob/master/src/Bunny/AbstractClient.php#L306 (Happens too often)

99% of times L306 throws exception
I think the issue is related to #58

@jakubkulhan I think https://github.com/jakubkulhan/bunny/blob/master/src/Bunny/AbstractClient.php#L306 is a mistake

According to http://php.net/manual/en/function.fwrite.php

fwrite() returns the number of bytes written, or FALSE on error.

Note:
Writing to a network stream may end before the whole string is written. Return value of fwrite() may be checked:

    <?php
    function fwrite_stream($fp, $string) {
        for ($written = 0; $written < strlen($string); $written += $fwrite) {
            $fwrite = fwrite($fp, substr($string, $written));
            if ($fwrite === false) {
                return $written;
            }
        }
        return $written;
    }
    ?>

@jakubkulhan any idea?

@sm2017 AbstractClient::write() is called repeatedly, until the whole buffer is flushed to the connection (https://github.com/jakubkulhan/bunny/blob/master/src/Bunny/Client.php#L83-L89).

If no bytes from the buffer have been written and fwrite() returns zero, it means the connection is broken. See first comment for fwrite() - http://php.net/manual/en/function.fwrite.php#96951

@jakubkulhan
See #58 again , why my connection broken after 0.5 second??

Can you provide code that would reproduce the problem?