thephpleague / flysystem-rackspace

Flysystem Adapter for Rackspace
37 stars 28 forks source link

PHP Warning: fclose(): xx is not a valid stream resource #7

Closed harikt closed 9 years ago

harikt commented 9 years ago

I was making use of the Rackspace adapter via flysytsem .

The code is as below .

$flysystem = new Filesystem(new RackspaceAdapter($container));
$fp = fopen($file, 'r+');
if ($fp) {
    $flysystem->writeStream($destination, $fp);
    fclose($fp);
}

I noticed when trying to close it says not a resource.

PHP Warning: fclose(): xx is not a valid stream resource in ...

Wonder whether flysystem at some point is automatically closing the same ?

Good thing is it is sending the data to the Cloud. So the file is already present on both local and server :) .

frankdejonge commented 9 years ago

@harikt Hi, this is something I know. The rackspace sdk closes the resource internally. Which is a unexpected side-effect. One should always first check if the resource is still valid before closing.

harikt commented 9 years ago

Thank you. Just wanted to mention it.

Hari K T

You can ring me : +91 9388 75 8821

http://harikt.com , https://github.com/harikt , http://www.linkedin.com/in/harikt , http://www.xing.com/profile/Hari_KT

Skype : kthari85 Twitter : harikt

On Fri, May 15, 2015 at 11:59 AM, Frank de Jonge notifications@github.com wrote:

@harikt https://github.com/harikt Hi, this is something I know. The rackspace sdk closes the resource internally. Which is a unexpected side-effect. One should always first check if the resource is still valid before closing.

— Reply to this email directly or view it on GitHub https://github.com/thephpleague/flysystem-rackspace/issues/7#issuecomment-102282242 .

dopesong commented 9 years ago

If I'm correct Amazon S3 SDK does the same.

So I think there should be mentioned that about it:

if (is_resource($stream)) {
    fclose($stream);
}
harikt commented 9 years ago

I do agree it will be nice to mention it.