Bug #70417 [Com]: PharData::compress() doesn't close temp file

From: Date: Wed, 04 Nov 2015 02:37:03 +0000
Subject: Bug #70417 [Com]: PharData::compress() doesn't close temp file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197006@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70417&edit=1

 ID:                 70417
 Comment by:         kalaychit55 at love dot com
 Reported by:        r-orlowski at o2 dot pl
 Summary:            PharData::compress() doesn't close temp file
 Status:             Analyzed
 Type:               Bug
 Package:            *Compression related
 Operating System:   Ubuntu 14.04 LTS
 PHP Version:        5.6.12
 Block user comment: N
 Private report:     N

 New Comment:

kalaychit55@love.com


Previous Comments:
------------------------------------------------------------------------
[2015-09-03 15:43:09] cmb@php.net

I've submitted PR #1500.

------------------------------------------------------------------------
[2015-09-03 14:24:44] cmb@php.net

Correction: closing of the temp file should only happen when
the Phar object is destroyed[1], but not earlier.

[1] <https://github.com/php/php-src/blob/php-5.6.12/ext/phar/phar.c#L288-L295>

------------------------------------------------------------------------
[2015-09-03 12:11:05] cmb@php.net

Indeed, when Phar::compress() is called a temporary file is
opened[1], but not closed[2] on success.

[1] <https://github.com/php/php-src/blob/php-5.6.12/ext/phar/phar_object.c#L2255>
[2] <https://github.com/php/php-src/blob/php-5.6.12/ext/phar/phar_object.c#L2342>

------------------------------------------------------------------------
[2015-09-03 10:34:26] r-orlowski at o2 dot pl

Description:
------------
I need to archive a lot (>1000 && <2000) of files into plenty small archives (~900)
via PHP application. I used PharData class to create archives. During script run I recieved
"failed to open dir: Too many open files" error. After debug my whole application I found
that calling PharData::compress() open some /tmp file that is never closed. Calling compress() in a
loop lead to rising count of open files. 


Test script:
---------------
<?php

function archiveDir($archiveName, $dir)
{
    system("lsof -p ".getmypid()." | wc -l");  // on my local host give 72
    $arch = new \PharData($archiveName);
    $arch->buildFromDirectory($dir);
    system("lsof -p ".getmypid()." | wc -l"); // on my local host give 73 -
buildFromDirectory open $dir
    system("lsof -p ".getmypid()." | grep /tmp/"); // empty result - no /tmp/
files open
    $arch->compress(\Phar::GZ);
    system("lsof -p ".getmypid()." | wc -l"); // on my local host give 74 -
compress open /tmp/phppI7yJX file
}

archiveDir("./testArchive.tar", "./");
system("lsof -p ".getmypid()." | wc -l"); // on my local host give 73 - $dir
opened by DirectoryIterator (line 7) is closed
system("lsof -p ".getmypid()." | grep /tmp/"); // we have still opened 
/tmp/phppI7yJX file

Expected result:
----------------
Last lsof call should return same count of open files as first call of lsof.

Actual result:
--------------
lsof called after archiveDir() show, that we have one more open file than before archiveDir() call


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=70417&edit=1


Thread (6 messages)

« previous php.bugs (#197006) next »