Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Avoid opening output stream twice #122

Closed

Conversation

mlocati
Copy link
Contributor

@mlocati mlocati commented Apr 13, 2017

When we set the outputstream option, the output file gets opened twice: here and here.

The second handle can be managed (eg closed) by accessing the Zend\Http\Response\Stream\getStream() method, but the first handle is simply lost: the file remains open (ie locked) until the end of the execution of the PHP script.

Let's reuse the first file handle.

@mlocati
Copy link
Contributor Author

mlocati commented Apr 26, 2017

I updated this PR by adding a test to check that we can delete the downloaded file (previously this assertion would have failed on Windows).

@@ -918,11 +923,17 @@ public function send(Request $request = null)
throw new Client\Exception\RuntimeException('Adapter does not support streaming');
}

$this->streamHandle = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that this code is relying on side effects

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a better suggestion?

weierophinney added a commit that referenced this pull request Apr 26, 2018
weierophinney added a commit that referenced this pull request Apr 26, 2018
@weierophinney
Copy link
Member

Thanks, @mlocati.

@mlocati mlocati deleted the hotfix/streamed-responses branch April 26, 2018 16:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants