CodeIgniter Forums
To resolve memory use issue in CodeIgniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: To resolve memory use issue in CodeIgniter (/showthread.php?tid=52110)



To resolve memory use issue in CodeIgniter - El Forum - 05-29-2012

[eluser]npCoda[/eluser]
I am facing problem of site break down. Since this is the site related to photos. It’s using almost 95% of memory of server. When it reaches to 100% the site is down. I checked from the profiler, and get following details:

Quote:Loading Time: Base Classes 0.0404
Controller Execution Time ( Events / Get Series Images ) 10.7655
Total Execution Time 10.8061

MEMORY USAGE : 3,948,864 bytes

For detail please see the attached file.

Here data are fetched from Progress server using JSON. I am surprise what made it so. But in my mind one thing hunt, why not to free the memory when work is done? I went to different forum of CI but could not get the answer.

I tried to use ob_end_flush(), ob_flush(),.. but could not get desire result. I am too is unaware about how to use in CI.

I hope I am able to clear my problem. Thank you in advance for the support.

I am using HMVC.

CODE

Code:
// controller
    public function get_event_images(){    
        // pagination
        $data['current_page'] = @$_GET['page'][email protected]$_GET['page']:1;

        $data['event_id'] = $this->uri->segment(3);  
        $data['event_name'] = urldecode($this->uri->segment(4));  
        $url = JSON_URL."jsread.p?call=treeimg&user;=&lang=en&tree;=".$data['series_id']."&sort=last&max;=".MAX_RECORD."&startpage;=".$data['current_page']."&pagesize;=".PAGE_SIZE;        
        $json_formated_data =  readJSONURL($url);  

        //extract array of images only
        $data['images'] = getData($json_formated_data);

        $image_stat = getImageStat($json_formated_data);
        $data['total_images']= $image_stat[6];  
        $data['total_rows'] = $image_stat[5];

        $data['main_content'] = 'eventimages';  
        $data['title'] = "Event Images";

        // store series details in session
        $newdata = array(
            'event_id'  =>$data['event_id'],
            'event_name'=> $data['event_name']
        );
        $this->session->set_userdata($newdata);

        $this->load->view('ktmevent/template_page', $data);        
    }



// view
    if(!empty($images)):
        foreach($images as $data):
            echo  "<li>";  
                echo  "<div class=\"image\">";  
                echo "<a >";
                echo "<img  />";
                echo "</a>";
                echo "</div>";
                echo "<div>";
                echo anchor('events/image_detail/'.$series_id.'/'.$data['Photono'], 'Detail');
                echo "</div>";
            echo "</li>";
        endforeach;
    endif;



To resolve memory use issue in CodeIgniter - El Forum - 05-29-2012

[eluser]CroNiX[/eluser]
Are you storing your images in the database?


To resolve memory use issue in CodeIgniter - El Forum - 05-29-2012

[eluser]npCoda[/eluser]
No, images are in different server folder. Only the image name and path are stored in Progress Database.


To resolve memory use issue in CodeIgniter - El Forum - 05-29-2012

[eluser]Aken[/eluser]
I'd suggest using the Benchmark library to profile your code and figure out where the most resources are being consumed. Then you can focus on trying to optimize that portion.


To resolve memory use issue in CodeIgniter - El Forum - 05-29-2012

[eluser]npCoda[/eluser]
As I am new to CI so I am unaware about Benchmark library. Can you please provide me guideline (may be link) so that I can easily configure.



To resolve memory use issue in CodeIgniter - El Forum - 05-29-2012

[eluser]InsiteFX[/eluser]
If you are using arrays make sure you unset them after you are finished with them.



To resolve memory use issue in CodeIgniter - El Forum - 05-29-2012

[eluser]Aken[/eluser]
[quote author="npCoda" date="1338358255"]As I am new to CI so I am unaware about Benchmark library. Can you please provide me guideline (may be link) so that I can easily configure.
[/quote]
Always search the User Guide if you don't recognize something. http://ellislab.com/codeigniter/user-guide/libraries/benchmark.html


To resolve memory use issue in CodeIgniter - El Forum - 05-29-2012

[eluser]npCoda[/eluser]
Thanks for suggestion, Aken.