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

File stream is dropped on writeStream() #113

Closed
violuke opened this issue Jun 23, 2020 · 5 comments
Closed

File stream is dropped on writeStream() #113

violuke opened this issue Jun 23, 2020 · 5 comments

Comments

@violuke
Copy link

violuke commented Jun 23, 2020

After using the writeStream() function, my file handle is no longer a valid stream resource. Other providers (I've tested specifically with S3) keep the handle as a valid resource. I hope that makes sense?

$someFile = tmpfile();

$filesystem->writeStream($remoteFileName, $someFile);

// This line causes a problem with this adapter, but not others
// Warning: fclose(): supplied resource is not a valid stream resource
fclose($someFile);
@radoslawkoziol
Copy link

@violuke You need to check if $someFile is a resource:

if (is_resource($someFile)) {
    fclose($someFile);
}

@violuke
Copy link
Author

violuke commented Sep 16, 2020

Thanks, yes, I know I can check, but I think it's a bug that this adapter works differently to the others?

@radoslawkoziol
Copy link

@violuke it appears to be normal behavior. According to the official Flysystem documentation:

Some SDK’s close streams after consuming them, therefore, before calling fclose on the resource, check if it’s still valid using is_resource.

https://flysystem.thephpleague.com/v1/docs/usage/filesystem-api/

@violuke
Copy link
Author

violuke commented Sep 16, 2020

You're right, sorry! Thanks for sending that link, that's really helpful. I'll close this as it's not a bug then 👍

@violuke violuke closed this as completed Sep 16, 2020
@shopmeister
Copy link

with php 8.x we should not use that anymore, just use

if (!$someFile) { fclose($someFile); }

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

3 participants