Motimot
Motimot

Reputation: 59

Zipping 400 files [php]

I made a code to zip 400 files from website, but when I open it, it taking a lot of time (And this is ok), but if it too long the php file stop working.

How I suppose to zip 4000 files without my website crash? Maybe I need to create a progress bar?

Hmm.. help? :)

Upvotes: 0

Views: 43

Answers (3)

BendaThierry.com
BendaThierry.com

Reputation: 2110

I think you should look around PHP set time limit or max_execution_time properties:

ini_set('max_execution_time', 300); 
// or if safe_mode is off in your php.ini
set_time_limit(0);

Try to find the reasonable settings for zipping all your bundle, and set the values accordingly.

The PHP interpreter is limited in its own execution time, by default to a certain value. That's why it stops suddently. If you change that setting at the beginning of your php script, it will work better, try it!

You could invoke the php executable in cli mode too, to handle that process... with functions like shell_exec

Upvotes: 0

Eloims
Eloims

Reputation: 5224

Long work (like zipping 4000 files, sending emails, ...) should not be done in PHP scripts that will keep the user's browser waiting.

Your user may cancel loading the page, and even if they don't, it's not great to have an apache thread locked during a long time.

Setting up a pool of workers outside of apache, to make this kind of work asynchronously is usually the way to go. Have a look at tools like RabbitMQ and Celery

Upvotes: 1

Loufylouf
Loufylouf

Reputation: 699

In a PHP installation, you have the directive max_execution_time which is defined in your php.ini file. This directive sets the maximum time of execution of any of your PHP scripts, so you might want to increase it or set it to the infinite (no time limit). You have two ways of doing that : you can modify your php.ini but it's not always available. You can also use the set_time_limit function or the ini_set function. Note that depending on your host service, you may not be able to do any of this.

Upvotes: 0

Related Questions