|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53467 Phar cannot compress large archives
Submitted: 2010-12-03 20:31 UTC Modified: 2021-01-26 17:02 UTC
Avg. Score:4.8 ± 0.6
Reproduced:27 of 28 (96.4%)
Same Version:1 (3.7%)
Same OS:5 (18.5%)
From: mep_eisen at web dot de Assigned: cmb (profile)
Status: Closed Package: PHAR related
PHP Version: 5.3.3 OS: Windows 7 - 64
Private report: No CVE-ID: None
 [2010-12-03 20:31 UTC] mep_eisen at web dot de
I tried to create a large phar (exactly 2347 files). However compressing the phar simply fails. That may be a similar problem as closed pecl bug:

Smaller phars are working. If using the commented section (compress them by hand) it does work but this is really slow.

Test script:
if (file_exists('D:\\Dev\\ws\\mavenphp-flow3\\FLOW3\\target'.DIRECTORY_SEPARATOR.'FLOW3-1.0.0-alpha-13.phar')) unlink('D:\\Dev\\ws\\mavenphp-flow3\\FLOW3\\target'.DIRECTORY_SEPARATOR.'FLOW3-1.0.0-alpha-13.phar');
$phar = new Phar('D:\\Dev\\ws\\mavenphp-flow3\\FLOW3\\target'.DIRECTORY_SEPARATOR.'FLOW3-1.0.0-alpha-13.phar', 0, 'FLOW3-1.0.0-alpha-13.phar');

//$localDir = realpath('D:\\Dev\\ws\\mavenphp-flow3\\FLOW3\\target\\classes\\Packages\\This\\FLOW3');
//$iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath('D:\\Dev\\ws\\mavenphp-flow3\\FLOW3\\target\\classes\\Packages\\This\\FLOW3')));
//foreach ($iter as $file)
//	$pathName = $file->getPathname();
//	$localName = substr($pathName, strlen($localDir));
//	$phar->addFile($pathName, $localName);
//	echo "adding $localName".PHP_EOL;
//	$phar[$localName]->compress(Phar::GZ);
$phar->buildFromIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath('D:\\Dev\\ws\\mavenphp-flow3\\FLOW3\\target\\classes\\Packages\\This\\FLOW3'))), realpath('D:\\Dev\\ws\\mavenphp-flow3\\FLOW3\\target\\classes\\Packages\\This\\FLOW3'));
echo "packed ".$phar->count()." files".PHP_EOL;
echo "compressing".PHP_EOL;
$phar->setStub('<?php die(\'Unable to execute this phar\'); __HALT_COMPILER(); ?>');

Expected result:
expected to get the phar.

Actual result:
BadMethodCallException: unable to create temporary file in D:\Dev\ws\mavenphp-fl
ow3\FLOW3\target\packagePhar.php on line 20

Call Stack:
    0.0011     332160   1. {main}() D:\Dev\ws\mavenphp-flow3\FLOW3\target\packag
    5.1570    1068784   2. Phar->compressFiles() D:\Dev\ws\mavenphp-flow3\FLOW3\


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-05 06:15 UTC] d dot kreuer at kremedia dot de
I have the same problem under Ubuntu 10.04.3 with PHP 5.3.5

PHP 5.3.5-1ubuntu7.2ppa1~lucid with Suhosin-Patch (cli) (built: May  7 2011 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v4.0.7, Copyright (c) 2002-2011, by ionCube Ltd.
    with Suhosin v0.9.29, Copyright (c) 2007, by SektionEins GmbH
 [2012-07-27 12:10 UTC] mep_eisen at web dot de
This bug is still present. The workarounds on large phar files are resulting high cpu-load and packaging phar in more than 30 mins.
 [2013-02-27 16:59 UTC]
Still present with PHP 5.4 as well (with Ubuntu 12.04).

PHP 5.4.12-1~quantal+1 (cli) (built: Feb 25 2013 19:19:48) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
 [2013-10-08 14:43 UTC] Tr at visPaul dot me
I also am seeing this problem in Fedora 19 Php 5.5.1. I found 2 workarounds and I'm curious if they works for others:

1. Don't attempt to compress the Phar. The compression seems to be the root of the issue and throws an exception: "unable to create temporary file"

2. Bump the number of max files that you can open by editing /etc/security/limits.conf or similar.

For whatever reason it seems that the Phar's compress method needs to open all of the files at once. Perhaps a Php Dev can shed some light on this and confirm/deny that it is a bug.
 [2015-03-04 16:06 UTC] kevin at herrera dot io
Here's a script that will trigger the bug:
(A person also narrowed down the affected C code for the phar extension: )



ini_set('memory_limit', -1);

$max_handles = (int) file_get_contents('/proc/sys/fs/file-max');

if (!is_dir('src')) {
    echo "Creating source files...\n";


    $total_dirs = ceil($max_handles / 1000);

    for ($current_dir = 0; $current_dir < $total_dirs; $current_dir++) {

        for ($current_file = 0; $current_file < 1000; $current_file++) {
} else {
    echo "Source files already exist, skipping.\n";

if (file_exists('bug.phar')) {
    echo "Removing previous phar...\n";


echo "Building new phar...\n";

$phar = new Phar('bug.phar');
    new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator(

echo "Compression files in phar...\n";

$phar = new Phar('bug.phar');
 [2015-05-28 10:10 UTC] hanskrentel at yahoo dot de

Bug #58169: "Number of files in the Phar" limited to 2042 (Apr 2008)
 [2018-09-30 16:50 UTC]
This is likely a duplicate of bug #70417.
 [2019-09-02 13:57 UTC] flavio dot lisboa at fgsl dot eti dot br
I have experienced this bug in Ubuntu 18.04LTS with php 7.2.19.
I removed temp file created by Phar class, but it still fails when compressFiles is called.
 [2021-01-26 17:02 UTC]
-Assigned To: +Assigned To: cmb
 [2021-01-26 17:03 UTC]
The following pull request has been associated:

Patch Name: Fix #53467: Phar cannot compress large archives
On GitHub:
 [2021-02-03 10:25 UTC]
Automatic comment on behalf of
Log: Fix #53467: Phar cannot compress large archives
 [2021-02-03 10:25 UTC]
-Status: Assigned +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 03:01:29 2024 UTC