Bug #53467 [Com]: Phar cannot compress large archives

From: Date: Thu, 28 May 2015 10:10:16 +0000
Subject: Bug #53467 [Com]: Phar cannot compress large archives
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192960@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=53467&edit=1

 ID:                 53467
 Comment by:         hanskrentel at yahoo dot de
 Reported by:        mep_eisen at web dot de
 Summary:            Phar cannot compress large archives
 Status:             Open
 Type:               Bug
 Package:            PHAR related
 Operating System:   Windows 7 - 64
 PHP Version:        5.3.3
 Block user comment: N
 Private report:     N

 New Comment:

Related:

Bug #58169: "Number of files in the Phar" limited to 2042 (Apr 2008)
https://bugs.php.net/bug.php?id=58169


Previous Comments:
------------------------------------------------------------------------
[2015-05-28 10:09:15] hanskrentel at yahoo dot de

Related To: Bug #58169

------------------------------------------------------------------------
[2015-03-04 16:06:41] 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);

------------------------------------------------------------------------
[2013-10-08 14:43:52] 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.

------------------------------------------------------------------------
[2013-02-27 16:59:11] 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

------------------------------------------------------------------------
[2012-07-27 12:10:16] 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.

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=53467


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


Thread (11 messages)

« previous php.bugs (#192960) next »