guzzle / psr7

PSR-7 HTTP message library
MIT License
7.88k stars 3 forks source link

Stream::getSize() should return null with popen streams #79

Closed Rudloff closed 8 years ago

Rudloff commented 8 years ago

Hello,

I am trying to work with popen streams like this:

$stream = \GuzzleHttp\Psr7\stream_for(
    popen(
        'ls', 'r'
    )
);

But $stream->getSize() always returns 0 which causes problems with the Slim framework (see https://github.com/slimphp/Slim/issues/1838).

PSR-7 says that getSize() should return null when the size is unknown, which seems to be the case here.

mtdowling commented 8 years ago

From what I understand, if popen streams return a valid size when calling fstat, then this would work.

How would Guzzle know it's a popen stream and not to trust the result of fstat?

Rudloff commented 8 years ago

I thought stream_get_meta_data() would return a different type for popen streams but it returns the same type as local file streams. So indeed there might not be a way to detect that it is a popen stream.

mtdowling commented 8 years ago

Closing as this does not seem possible.

llvdl commented 8 years ago

Should this be reopened, since a solution is proposed in issue #1838? A similar issue is posted at the Slim project, where a solution is proposed: https://github.com/slimphp/Slim/issues/1838

iget-master commented 7 years ago

I agree that this should be reopened and implement the proposed solution.