SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Taunton, UK
    Posts
    787
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Zipping files on the server

    I need to implement some functionality on my site that allows the use to create a library of files and then click a button to download them.

    Some of the files are fairly large so the total size of all the files needing zipped could be as much as 500MB if not more.


    So my first question: Is this feasible to do using PHP or would these large file sizes cause memory errors on the server? Note the site is on a VPS.

    If it is possible, can you suggest how to achieve this and what the most efficient way to do it is.

    Ideally I would like the zip to automatically download to the users PC when it has been created.

    Any advice much appreciated.

    Thanks
    Mediakitchen Limited
    App Development | Website Design & Development | Flash Game Development
    Somerset, UK
    http://www.mediakitchen.co.uk

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,169
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    You will likely run into a slew of issues
    1) Memory Size, definitely an issue here
    2) The browser will likely time out in the process of zipping that much data

    What I have personally done in the past, is I hand off that task to a cronjob that runs every X minutes. It picks up a file that explains what needs to be done, list of files, e-mail of person requesting the download, etc. It reads the file, creates the zip using a shell script, passes the location of the zip and the e-mail address to a PHP script, that kicks an email to the user with a download link.

    I then have a cleanup script that removes the zip file after X number of hours/days.

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Taunton, UK
    Posts
    787
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the swift reply cpradio

    Yeah I suspected there would be problems.

    My site specification requires the zip files are delivered via the browser - would there be a way of creating the zip using the shell script immediately and then displaying a download link or automatically downloading the zip to the users hard drive?
    Mediakitchen Limited
    App Development | Website Design & Development | Flash Game Development
    Somerset, UK
    http://www.mediakitchen.co.uk

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,169
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    You can run a system() or exec() command to build the zip file (thus releasing the Memory issue from PHP), but I still have my doubts that the zip will be ready before the browser times out on the page execution.

    You can introduce a polling technique, where you use an Ajax script or a refreshing iframe to check if the process is done, and then load up the download link as well. I find that technique a lot more messy and harder to debug/maintain, but others seem to like it...

  5. #5
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Taunton, UK
    Posts
    787
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks cpradio

    I assume the page execution time out time is an element out of my control?

    The Ajax polling does sound quite messy but it may be my only option:

    Thanks for the very helpful advice
    Mediakitchen Limited
    App Development | Website Design & Development | Flash Game Development
    Somerset, UK
    http://www.mediakitchen.co.uk

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,169
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    Yes (in most cases), however you can set a time out period on the server level (in .NET you can even set it on the application level, php check out this thread), but most users always expect an immediate result and would likely close the window, hit the back button, hit refresh, etc while waiting over a minute for the page to load.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •