Home >Backend Development >PHP Tutorial >CakePHP: Performance Considerations_PHP Tutorial

CakePHP: Performance Considerations_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:43:40871browse

1. Use of $uses and loadModel

Try not to use $uses in CakePHP 1.3.x version, because this will load all the used models, occupy memory and consume unnecessary time.

On the contrary, where you need to use the model, use loadModel to load it. If no associated data is required, set its recursive property to -1.

In addition, the default data model of the controller does not need to be loaded. If users_controller does not call loadModel(User), the User model and its associated models will be loaded automatically,

Just use it directly in the controller:

$this->User... ;

$this->User->Role...

Use lazy loading technology, version 1.3 has a lazy_model, replace the base class of your app_model with LazyModel,

will cause the model to be loaded only where it is actually called.

2. Use of eval and requestAction

Try not to use eval and requestAction. eval will cause a new script parsing process, and requestAction is equivalent to 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 is replaced with view/helper

3. Cache

Use memcached where distributed data sharing is required, and try to use Apc for local data. Where Cache::write/read is used, specify which Cache configured in core.php is used through parameters.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478816.htmlTechArticle1. The use of $uses and loadModel. Try not to use $uses in CakePHP1.3.x version, because this All used models will be loaded, occupying memory and unnecessary time. On the contrary, when you need to use...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn