|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70417 PharData::compress() doesn't close temp file
Submitted: 2015-09-03 10:34 UTC Modified: 2017-01-05 17:53 UTC
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: r-orlowski at o2 dot pl Assigned: cmb (profile)
Status: Closed Package: *Compression related
PHP Version: 5.6.12 OS: Ubuntu 14.04 LTS
Private report: No CVE-ID: None
 [2015-09-03 10:34 UTC] r-orlowski at o2 dot pl
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:

function archiveDir($archiveName, $dir)
    system("lsof -p ".getmypid()." | wc -l");  // on my local host give 72
    $arch = new \PharData($archiveName);
    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
    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


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-03 12:11 UTC]
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: cmb
 [2015-09-03 12:11 UTC]
Indeed, when Phar::compress() is called a temporary file is
opened[1], but not closed[2] on success.

[1] <>
[2] <>
 [2015-09-03 12:27 UTC]
-Summary: \PharData::compress lead to "too many open files" +Summary: PharData::compress() doesn't close temp file
 [2015-09-03 14:24 UTC]
Correction: closing of the temp file should only happen when
the Phar object is destroyed[1], but not earlier.

[1] <>
 [2015-09-03 15:43 UTC]
-Assigned To: cmb +Assigned To:
 [2015-09-03 15:43 UTC]
I've submitted PR #1500.
 [2017-01-05 17:52 UTC]
Automatic comment on behalf of
Log: Fix #70417: PharData::compress() doesn't close temp file
 [2017-01-05 17:52 UTC]
-Status: Analyzed +Status: Closed
 [2017-01-05 17:53 UTC]
-Assigned To: +Assigned To: cmb
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 21:01:33 2024 UTC