开发者

PHP zip archive progress bar

I've googled for this but didn't find any solution - is there a way to create a progessbar for adding/extracti开发者_如何学Pythonng files to/from zip archive in PHP? Can I get some kind of status message which I can than get with an AJAX request and update the progress bar?

Thanks.


I am trying to do the same thing at the moment; it is mostly* complete (*see issues section below).

The basic concept I use is to have 2 files/processes:

  1. Scheduler (starts task and can be called to get updates)
  2. Task (actually completes the task of zipping)

The Scheduler will:

  1. Create a unique update token and save to cache (APC)
  2. Call the Task page using curl_multi_exec which is asynchronous, passing update_token
  3. Return the token in JSON format OR
  4. Return the contents of the APC under the update_token (in my case this is a simple status array) as JSON

The Task will:

  1. Update the APC with status, using the update token
  2. Do the actual work :)

Client-side

You'll need some JavaScript to call the Scheduler, get the token in return, then call the Scheduler, passing update_token, to get updates, and then use these returned values to update the HTML.

** Potential pitfalls**

Sessions can be a problem. If you have the same session you will notice that your browser (or is this Apache?) waits for the first request in the session to complete before returning others. This is why I store in the APC.

Current Issues

The problem with the ZipArchive class is that it appears to all the grunt work in the ->close() method, whilst the addFile method appears to take little to no time to complete.

As a workaround you can close and then reopen the archive at specific byte or file intervals. This actually slows the process of zipping down a little, but in my case this is acceptable, as the visual progress bar is better than just waiting with no indication of what is happening.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜