user2553381
user2553381

Reputation: 5

Can I set max execution time in php.ini to be 30,000 in my case?

Scenario is that I wanna save 4046 images to a folder . (Have coded in php ) I guess it would take maximum of 5 hours . Initially max execution time in php.ini was set to 30 seconds . After 650 images got saved , The browser froze . And none of the images got saved .But the process was running . And had no error too . Can anybody give me an idea the max execution time I should set in this case !

P.S. If my approach is wrong , Do guide me . Thanks

Upvotes: 0

Views: 1220

Answers (3)

rfoo
rfoo

Reputation: 1198

I'd highly suggest modifying your script to do the job incrementally. So basically break the job up into smaller parts and provide a break in between. The basic logic flow would be like this.

<?php
$start = $_GET['start']; //where to start the job at
$end = $start + 250; //queue this and the next 250 positions
for($i=$start;$i<=$end;$i++){
    //do the operations need for position $i
}
header("/urlToScript?start=".($end+1)); //refresh page moving to the next 250 jobs
?>

This will do small parts of the total job and avoid any issues with the interpreter. Add any INI modifications to increase memory usage and time as needed and you'll be fine.

Upvotes: 0

ogur
ogur

Reputation: 4586

I'm not sure if your problem isn't caused just by wrong tool - PHP isn't meant for such long tasks.
If that images are on some server better user FTP client.
If you have list of files saved in text file use cURL to download them.

Upvotes: 1

Iqbal Malik
Iqbal Malik

Reputation: 602

You can extend the time using this line at that script which saving images.

ini_set('max_execution_time', 30000);

Second approach is to use htaccess.

php_value max_execution_time 30000

Upvotes: 0

Related Questions