CakePHP: Performance Considerations _php Tutorial

Source: Internet
Author: User
1. Use of $uses and Loadmodel

Try not to use $uses in the cakephp1.3.x version, as this will load all the model used, consume memory and consume unnecessary time.

Instead, use Loadmodel to load it where you need to use the model. Set its Recursive property to-1 without the need for associated data.

In addition the controller default data model does not load, if Users_controller does not call Loadmodel (user), the user model and its associated model will be loaded automatically,

Just use it directly in the controller:

$this->user ...;

$this->user->role ...

Using the lazy loading technology, version 1.3 has a lazy_model that converts your App_model base class to Lazymodel,

will allow the model to actually load only where it is actually called.

2. Use of Eval and requestaction

Try not to use eval and requestaction. Eval causes a new script parsing process, and requestaction is the equivalent of issuing a new request.

Eval can be replaced with {} or $$ similar syntax, such as

Case 1

$this->{$this->modelclass}->hasfield ("country_id");

-----------------------------------------------------------------

Case 2

$foo = City;

$ $foo = Shanghai;

Requestaction Replace with View/helper

3. Cache

Where distributed data sharing is required, local data is used as memcached as possible with APC. Use parameters to specify which cache is configured in core.php using the Cache::write/read.

http://www.bkjia.com/PHPjc/478816.html www.bkjia.com true http://www.bkjia.com/PHPjc/478816.html techarticle 1, the use of $uses and Loadmodel in the cakephp1.3.x version as far as possible not to use $uses, because this will all load the model used to occupy memory and consume unnecessary time. Contrary to the need to make ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.