Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #6749

Re: problem in creating Zip file

From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: problem in creating Zip file
Date 2012-08-09 07:09 +0200
Message-ID <a8guvuF1f7U1@mid.individual.net> (permalink)
References <1592f3dd-f681-4100-b6b4-e1684b06322c@googlegroups.com>

Show all headers | View raw


Supriya wrote:
> Hi All
> i m trying to create a Zip file of 1 folder which contains 2 folders and 33 files but the resulted zip file only contains 21 file and 1 folder.And when i open the files of zip folder it says files r corrupted.
>
> Here is my code:
> Plz help me to find out what is wrong there...
>
> <?php
>
> include("variable.php");
>
> ini_set("max_execution_time", 18000);

This will not help you, and as Jerry pointed out you may not be allowed to 
change the value.

Sure, the issue may be that the execution of the script needs more time, but 
you totally have forgot that there is a timeout in your browser, and when your 
browser times out, then the script will stop running on the server too and you 
end up with an unfinished job.

>
> // create object
>
> $zip = new ZipArchive();
>
> // open archive
>
> if ($zip->open($outputfoldername . ".zip", ZIPARCHIVE::CREATE) !== TRUE) {
> die ("Could not open archive");
> }
>
> // initialize an iterator
> // pass it the directory to be processed
>
> $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($outputfoldername . "/"));
>
> // iterate over the directory
> // add each file found to the archive
>
> foreach ($iterator as $key=>$value) {
> $zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");

if you make some output here, then you will extend the life for your 
connection, unless one iteration takes too long time.

> }
>
> // close and save archive
>
> $zip->close();
> echo "Archive created successfully.";
> ?>

If you can, make a cron job of this instead (not many web hotels does offer 
customers to run cron jobs), the job reads from a database table which jobs it 
has to do, it takes the oldest one in the list each time it's run (set it to 
run every 5 or 10 minutes) and marks it to be worked on, so that no other 
instance will try to do the same time if it takes longer than the time you set 
between two jobs, and when the process is finished, mark the job as finished 
(this gives you the possibility to check for jobs which fails, specially if 
you also set the time when the job changed state).

Then in the web ui you just have a way to put jobs into the queue.

You get a lot more stable system this way.


-- 

   //Aho

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

problem in creating Zip file Supriya <singla.supriya88@gmail.com> - 2012-08-07 23:40 -0700
  Re: problem in creating Zip file Doug Miller <doug_at_milmac_dot_com@example.com> - 2012-08-08 14:18 +0000
    Re: problem in creating Zip file Christoph Becker <cmbecker69@gmx.de> - 2012-08-08 16:37 +0200
      Re: problem in creating Zip file Jerry Stuckle <jstucklex@attglobal.net> - 2012-08-08 11:25 -0400
      Re: problem in creating Zip file Doug Miller <doug_at_milmac_dot_com@example.com> - 2012-08-08 17:46 +0000
  Re: problem in creating Zip file salil.ag@gmail.com - 2012-08-08 21:37 -0700
  Re: problem in creating Zip file "J.O. Aho" <user@example.net> - 2012-08-09 07:09 +0200
  Re: problem in creating Zip file "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-08-12 19:25 +0200

csiph-web