Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientException #59

Open
sm2017 opened this issue Feb 18, 2018 · 5 comments
Open

ClientException #59

sm2017 opened this issue Feb 18, 2018 · 5 comments

Comments

@sm2017
Copy link

sm2017 commented Feb 18, 2018

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

@sm2017
Copy link
Author

sm2017 commented Feb 18, 2018

@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
Copy link
Author

sm2017 commented Feb 21, 2018

@jakubkulhan any idea?

@jakubkulhan
Copy link
Owner

@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

@sm2017
Copy link
Author

sm2017 commented Feb 21, 2018

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

@jakubkulhan
Copy link
Owner

Can you provide code that would reproduce the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants