Welcome Guest, Not a member yet? Register   Sign In
Memory leak with Zip Encoding Class
#1

[eluser]OyoKooN[/eluser]
Hello,

On my project, I use the Cart Class to store photos the user wants to download.
When the user has finished, he push a button and my script creates a zip file with all the photos he chose.

It works fine the 2-3 first times but after, I get the following error from the PHP log file.

Quote:[27-Jul-2010 02:18:16] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 90038607 bytes) in C:\UwAmp\www\glenphotos\system\libraries\Zip.php on line 275

[27-Jul-2010 02:18:16] PHP Stack trace:

[27-Jul-2010 02:18:16] PHP 1. {main}() C:\UwAmp\www\glenphotos\index.php:0

[27-Jul-2010 02:18:16] PHP 2. require_once() C:\UwAmp\www\glenphotos\index.php:115

[27-Jul-2010 02:18:16] PHP 3. call_user_func_array() C:\UwAmp\www\glenphotos\system\codeigniter\CodeIgniter.php:236

[27-Jul-2010 02:18:16] PHP 4. Cart->download() C:\UwAmp\www\glenphotos\system\codeigniter\CodeIgniter.php:0

[27-Jul-2010 02:18:16] PHP 5. CI_Zip->archive() C:\UwAmp\www\glenphotos\application\controllers\cart.php:250

[27-Jul-2010 02:18:16] PHP 6. CI_Zip->get_zip() C:\UwAmp\www\glenphotos\system\libraries\Zip.php:304

Here is the code I use in my controller.

Code:
function download() {
        
        $this->load->model('photos_model');
        $this->load->library('zip');
        
        foreach ($this->cart->contents() as $items) {
            
            foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value) {
                
                if ($option_name == 'type' && $option_value == 1) {
                    
                    $path = './uploads/' . $items['name'];
                    $this->zip->read_file($path);
                    
                }
                elseif ($option_name == 'type' && $option_value == 2) {
                    
                    $photos = $this->photos_model->load_album_photos($items['id']);
                    
                    foreach ($photos as $photo) {
                        
                        $path = './uploads/' . $photo->pho_name;
                        $this->zip->read_file($path);
                        
                    }
                    
                }
                
            }
            
        }
        
        $path = './downloads/glen_photos_' . time() . '.zip';
        
        $this->zip->archive($path);
        
        $this->cart->destroy();
        
        $this->zip->download($path);
        
        $this->zip->clear_data();
        
    }

Thank you for your help.
#2

[eluser]OyoKooN[/eluser]
Okay, I changed my PHP.ini and it's fine now.




Theme © iAndrew 2016 - Forum software by © MyBB