php.net |  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
Votes:28
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mep_eisen at web dot de
New email:
PHP Version: OS:

 

 [2010-12-03 20:31 UTC] mep_eisen at web dot de
Description:
------------
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: http://pecl.php.net/bugs/bug.php?id=13727

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

Test script:
---------------
<?php
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');
$phar->startBuffering();

//$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->compressFiles(Phar::GZ);
$phar->setStub('<?php die(\'Unable to execute this phar\'); __HALT_COMPILER(); ?>');
$phar->stopBuffering();


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
ePhar.php:0
    5.1570    1068784   2. Phar->compressFiles() D:\Dev\ws\mavenphp-flow3\FLOW3\
target\packagePhar.php:20

Patches

Pull Requests

Pull requests:

History

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 
03:15:14) 
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] cicerchia@php.net
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: https://github.com/box-project/box2/issues/80#issuecomment-77147371 )

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

<?php

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";

    mkdir('src');

    $total_dirs = ceil($max_handles / 1000);

    for ($current_dir = 0; $current_dir < $total_dirs; $current_dir++) {
        mkdir("src/$current_dir");

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

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

    unlink('bug.phar');
}

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

$phar = new Phar('bug.phar');
$phar->buildFromIterator(
    new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator(
            'src',
            FilesystemIterator::SKIP_DOTS
        )
    ),
    'src'
);

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

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

Bug #58169: "Number of files in the Phar" limited to 2042 (Apr 2008)
https://bugs.php.net/bug.php?id=58169
 [2018-09-30 16:50 UTC] cmb@php.net
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] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2021-01-26 17:03 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #53467: Phar cannot compress large archives
On GitHub:  https://github.com/php/php-src/pull/6643
Patch:      https://github.com/php/php-src/pull/6643.patch
 [2021-02-03 10:25 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=1bb2a4f91cfde36ba343184f3d88189e646cc363
Log: Fix #53467: Phar cannot compress large archives
 [2021-02-03 10:25 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC