bunny icon indicating copy to clipboard operation
bunny copied to clipboard

ClientException

Open sm2017 opened this issue 6 years ago • 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 https://github.com/jakubkulhan/bunny/issues/58

sm2017 avatar Feb 18 '18 07:02 sm2017

@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;
    }
    ?>

sm2017 avatar Feb 18 '18 09:02 sm2017

@jakubkulhan any idea?

sm2017 avatar Feb 21 '18 07:02 sm2017

@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 avatar Feb 21 '18 08:02 jakubkulhan

@jakubkulhan See https://github.com/jakubkulhan/bunny/issues/58 again , why my connection broken after 0.5 second??

sm2017 avatar Feb 21 '18 16:02 sm2017

Can you provide code that would reproduce the problem?

jakubkulhan avatar Feb 21 '18 17:02 jakubkulhan