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

Error - Unexpected end of stream #56

Closed
jimmcq opened this issue Aug 6, 2016 · 21 comments
Closed

Error - Unexpected end of stream #56

jimmcq opened this issue Aug 6, 2016 · 21 comments

Comments

@jimmcq
Copy link

jimmcq commented Aug 6, 2016

With a fresh install, I tried to up RetrievePokemonCountExample.php (after updating the auth info) and get the error below:

PHP Fatal error: Uncaught exception 'Exception' with message 'read_bytes(): Unexpected end of stream' in vendor/nicklasw/pogoprotos-php/src/protocolbuffers.inc.php:364

This happens with many of the other example scripts as well.

@NicklasWallgren
Copy link
Owner

@DrDelay It's due the StreamWrapper. hmm, do you have any thought about it?

@DrDelay
Copy link
Collaborator

DrDelay commented Aug 6, 2016

I can't reproduce it at f70c9ce . I tried PlayerProfile and PokemonCount example, both worked.

@jimmcq
Copy link
Author

jimmcq commented Aug 6, 2016

I'm using PTC auth, if that matters... Other than that, it's unmodified fresh code (git clone, composer install) at f70c9ce

@NicklasWallgren
Copy link
Owner

Weird, I could reproduce the problem. Reverted the pull request until we find out what's causing the problem.

@jmcquillan Try the latest commit.

@jimmcq
Copy link
Author

jimmcq commented Aug 6, 2016

e8d58cc works for me!

@DrDelay
Copy link
Collaborator

DrDelay commented Aug 6, 2016

What is your guys environment?
I got PHP 7.0.9 NTS

@NicklasWallgren
Copy link
Owner

Tried both PHP 7.0.3-13 ( NTS ) and PHP 7.0.9-1 ( NTS ). Same issue.

What OS are you using?

@DrDelay
Copy link
Collaborator

DrDelay commented Aug 6, 2016

Windows 7, but I just tried it on a Debian Jessie with a PHP 7.0.9-1~dotdeb+8.1 (cli) ( NTS ) setup, worked aswell 😆

@NicklasWallgren
Copy link
Owner

I'm running Ubuntu 14.04. I love these sort of problems... :D

@DrDelay
Copy link
Collaborator

DrDelay commented Aug 6, 2016

The condition for the Exception is if (strlen($bytes) !== $len), where $bytes = fread($fp, $len), this text seems a bit misleading. I'm only thinking out loud, can this be character encoding related or something? Like, regional setting of the machine?

@NicklasWallgren
Copy link
Owner

I was thinking the same, it's probably related to encoding. It usually is.

@DrDelay
Copy link
Collaborator

DrDelay commented Aug 6, 2016

  • mbstring is not relevant (tried dis-/enable)
  • Windows is German, en_US:en on Debian
  • curl 7.49.1 on Windows, curl 7.38.0 on Debian

@jimmcq
Copy link
Author

jimmcq commented Aug 6, 2016

en_US PHP 5.6.24 on Mac OS 10.11.6 with curl 7.43.0

@NicklasWallgren
Copy link
Owner

The length of the string returned from stream_get_contents differs between the different streams.

94 (ProtobufIO::toStream)
139-141 (Streamwrapper::getResource)

@DrDelay
Copy link
Collaborator

DrDelay commented Aug 6, 2016

Regarding the mbstring that like I hastily said doesn't matter, I found a comment that says one should use mb_strlen($data, '8bit') to get the amount of bytes read (as strlen may be overloaded by the mbstring-ext, using mb_internal_encoding()). I cannot test whether that would fix it, but I can say that it still works with this in my environment. Can someone of you try it out?

@DrDelay
Copy link
Collaborator

DrDelay commented Aug 6, 2016

If so and this means we'd have to force every user to use mbstring-ext, it may be reasonable to just pass it as a string as this works. I'd still like to figure out the reason of this error.

@NicklasWallgren
Copy link
Owner

Nice find, mb_strlen($data, '8bit') did unfortunately no difference.

@DrDelay
Copy link
Collaborator

DrDelay commented Aug 6, 2016

I'm kinda out of ideas then.

I added this code to your unmarshall-method:

        // Unmarshall the response

        echo mb_internal_encoding(), PHP_EOL;
        echo mb_http_output(), PHP_EOL;
        echo mb_http_input(), PHP_EOL;
        echo mb_regex_encoding(), PHP_EOL;
        $body = $response->getBody();
        echo 'strlen(body->getContents): ', strlen($body->getContents()), PHP_EOL;
        $body->seek(0);
        echo 'body->getSize: ', $body->getSize(), PHP_EOL;
        $body->seek(0);
        $wrap = \GuzzleHttp\Psr7\StreamWrapper::getResource($body);
        echo 'strlen(streamwrapped): ', strlen(stream_get_contents($wrap)), PHP_EOL;
        $body->seek(0);
        echo 'strlen(toStream): ', strlen(stream_get_contents(\ProtobufIO::toStream($response->getBody()->getContents()))), PHP_EOL;
        die();

That results in:

UTF-8
UTF-8

UTF-8
strlen(body->getContents): 141
body->getSize: 141
strlen(streamwrapped): 141
strlen(toStream): 141

I'm assuming you get different sizes. Maybe you could run that and see what encodings you get.

@NicklasWallgren
Copy link
Owner

NicklasWallgren commented Aug 7, 2016

Hmm, the problem disappeared after re-installing the dependencies. It could be a bug connected to Guzzle.

Sorry for the late reply, been kind busy today.

@finalpk
Copy link

finalpk commented Aug 9, 2016

I got the same error with one of my accounts, however it works with my other account

I get this on the working account:

UTF-8
UTF-8
UTF-8 

strlen(body->getContents): 140 
body->getSize: 140
strlen(streamwrapped): 140
strlen(toStream): 140

and this on the one thats not working:

UTF-8
UTF-8
UTF-8

strlen(body->getContents): 141
body->getSize: 141
strlen(streamwrapped): 141
strlen(toStream): 141

@DrDelay DrDelay mentioned this issue Aug 9, 2016
@NicklasWallgren
Copy link
Owner

@finalpk Can you reproduce the problem in the latest version?

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

4 participants