×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

ZipArchive::close is terribly slow when executed by Apache2

ZipArchive::close is terribly slow when executed by Apache2

ZipArchive::close is terribly slow when executed by Apache2

(OP)
I'm creating a zip archive using PHP's ZipArchive functions. My code performs well enough on small archives but on larger jobs, the time difference between running the PHP script from the shell and running it from a browser is just ridiculous.

The script below, for instance, executes in ~37 seconds from the shell but takes a whopping ~18 minutes when called with a browser. (It may seem nonsensical to be zipping a zip file, but I'll actually be zipping a collection of different file types (which often include zip files) and in this case, the 353MB zip file is the bottleneck so that's what I'm testing with.)

I've tried using PHP's exec() to zip the file using the OS's zip function with similar results. The code was fast in the shell but slowed to a crawl when executed by a browser.

I've found a few references to similar issues online, but none with a resolution. Does anyone have an idea why running this code with a browser results in a 3,000% performance hit?

I'm only using zip to package a collection of files for download and don't really care if the archive is compressed. Tar might be a viable choice, but end users won't know what to do with a tar file, and tgz is also off the table for the same reason. I'm open to another packaging format but off the top of my head, I can't think of another packaging method as ubiquitous as Zip.

Any thoughts?

CODE

<?php
$zip = new ZipArchive;
$f = array('attach/service/2016/02/12200/353MB.zip');

if($zip->open('test.zip',false ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) === true) {

    foreach($f as $file)
    {
        $zip->addFile($file);
    }

    $zip->close();

    echo "ok\n";
} else {
    echo "failed\n";
} 

RE: ZipArchive::close is terribly slow when executed by Apache2

Hi

Quote (cmayo)

I'm only using zip to package a collection of files for download and don't really care if the archive is compressed.
Then try ZipArchive::CM_STORE :

CODE --> PHP

<?php
$zip = new ZipArchive;
$f = array('attach/service/2016/02/12200/353MB.zip');

if($zip->open('test.zip',false ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) === true) {

    foreach($f as $file)
    {
        $zip->addFile($file);
        $zip->setCompressionName($file, ZipArchive::CM_STORE);
    }

    $zip->close();

    echo "ok\n";
} else {
    echo "failed\n";
} 

Feherke.
feherke.github.io

RE: ZipArchive::close is terribly slow when executed by Apache2

(OP)
Thanks for the reply! I got my hopes up for a minute, but it looks like setCompressionName was introduced as of PHP 7 and we're still on 5.6. I probably should have mentioned that in my post.

RE: ZipArchive::close is terribly slow when executed by Apache2

(OP)
I think I've determined that the bottleneck lies with my shared hosting provider. The code runs in 20 seconds on my home Ubuntu box. I've opened a ticket with them.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close