Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7447731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:42:29+00:00 2026-05-29T12:42:29+00:00

I have a performance problem in Cake, generating images. The problem is when the

  • 0

I have a performance problem in Cake, generating images. The problem is when the controller function is called Cake makes a connection to the DB and the images load in “sync”, waiting to close the last connection (image per image load with a .5 sec wait).

Here is my controller:

class ThumbnailController extends AppController {
    var $uses       = null;
    var $components = array();
    var $autoRender = false;


    ###########################################################
    # PUBLIC
    ###########################################################

    public function thumb($folder = null, $w=0, $h=0, $filename=null){
        $this->thumbnail("default.jpg", $folder, $w, $h, $filename);
    }

    public function thumbMama($folder = null, $w=0, $h=0, $filename=null){
        $this->thumbnail("iconopersonadh.png", $folder, $w, $h, $filename);
    }

    ###########################################################
    # PRIVATE
    ###########################################################

    private function thumbnail($default_image, $folder = null, $w=0, $h=0, $filename=null){

        session_write_close();

        $img = WWW_ROOT.DS.$folder.DS.$filename;

        if(!is_file($img)){
            $img = WWW_ROOT.DS."img".DS.$default_image;
        }

        $img_info    = pathinfo($img);
                $filename    = $img_info["filename"];
                $extension   = strtolower($img_info["extension"]);
        $tn_filename = "tn-".$filename."-".$w."x".$h.".".$extension;

        switch($extension){
            case "gif":
                header('Content-type: image/gif');
            break;
            case "png":
                header('Content-type: image/png');
            break;
            default:
                header('Content-type: image/jpeg');
            break;
        }

        # COMPROBAMOS SI EXISTE UNA IMAGEN CACHEADA PARA NO GENERAR EL RECORTE AL VUELO
        if(is_file(WWW_ROOT.DS."files".DS."tn".DS.$tn_filename)){
            readfile(WWW_ROOT.DS."files".DS."tn".DS.$tn_filename);
        }else{

            $magic = new Imagick($img);
            $magic->cropThumbnailImage($w, $h);
            $magic->writeImage(WWW_ROOT.DS."files".DS."tn".DS.$tn_filename);
            echo $magic;

            //$this->log($img_info["basename"]." ---> ".$tn_filename, 'thumbnails-'.date("Ym"));
        }
    }

I need to force CakePHP to not load any DB or make a connection, to force the function to make only the code with no “lag”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:42:32+00:00Added an answer on May 29, 2026 at 12:42 pm

    If you put (or already have) this action in a seperate Controller, just put the following in it’s Model to avoid any database operations:

    class Thumbnail extends AppModel {
    
        public $useTable = false; // Don't use any db table
    
    }
    

    Further details about this are in the Cookbook.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a performance problem related to string comparison (in Java). I'm working on
I have a performance problem on a query. First table is a Customer table
I have got a performance problem about TextField.htmlText +=msg .And I know that TextField.appendText(msg)
I have a serious performance problem. I have a database with (related to this
Does windows have performance counters to measure statistics of a dialup connection? Opening up
I think I have a performance problem in my apache server. I have apache
In one of the apps of mine I have a performance problem I can’t
I have a strange performance problem with a query used to create a filter
I recently had to troubleshoot a performance problem with a slow grid load. Upon
Question: I have some performance problem in my app - and the bottleneck is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.