wiztrust / php-reader

Automatically exported from code.google.com/p/php-reader
0 stars 0 forks source link

File handles aren't closed on ISO14496 object destruction #66

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm batch renaming/moving files based on ISO14496 metadata but I get an error 
because file handles aren't closed on object destruction.

Original issue reported on code.google.com by suro...@gmail.com on 5 Mar 2012 at 5:33

GoogleCodeExporter commented 9 years ago
I am not sure whether the class should actually close the stream. However, you 
can do that yourself by passing a reference to a stream to the class and then 
manually close it after using the class. Try something like this:

{{{
<?php
while (<something to loop>) {
    $reader = new Zend_Io_FileReader($filename);
    $iso = new Zend_Media_Iso14496($reader);
    ...
    // do something
    ...
    $iso = null; //destroy object ref
    $reader->close(); //close stream
}
}}}

I could perhaps add some code to close the stream automatically if the stream 
was opened by the class.

Original comment by svollbehr on 5 Mar 2012 at 7:04

GoogleCodeExporter commented 9 years ago
Okay, changes made to subversion. Check out the repo and test with the latest 
code whether it works as you'd expect.

Original comment by svollbehr on 5 Mar 2012 at 7:07

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Your first workaround works, and I was using something similar. The change you 
made to the class doesn't work as expected, this is the code i tried:
<?php
    require_once 'Zend/Media/Iso14496.php';
    $fn = 'c:\\videos\\test.mp4';

    $isom = new Zend_Media_Iso14496($fn);
    unset($isom);
    rename($fn, $fn.'.test');
?>

Btw setting to null like you did in your example doesn't destroy the object's 
reference, although that was what I remembered too, but 
xdebug_debug_zval('isom') still says refcount=1. They must have changed at some 
point 'cause that's what these clowns do, they keep changing PHP's behaviour 
and you end up spending days investigating obscure behavior :( ... so much for 
efficiency. Using unset() does destroy the reference, not that it matters much 
'cause the GC still doesn't call the destructor until the script ends. I saw on 
some site someone said that even if you unset, your object might still be 
referenced by something other than a variable (??!!?). He didn't say what, and 
tbh I don't even care anymore.

Anyway man, thanks for your time and for your library, it's very useful :)
Cheers.

Original comment by suro...@gmail.com on 15 Mar 2012 at 5:12