Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
958aeb76
Commit
958aeb76
authored
May 05, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more on performance tuning
parent
aed66bcd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
11 deletions
+73
-11
performance.md
docs/guide/performance.md
+73
-11
No files found.
docs/guide/performance.md
View file @
958aeb76
...
...
@@ -14,15 +14,22 @@ Preparing framework for production
First thing you should do before deploying your application to production environment
is to disable debug mode. A Yii application runs in debug mode if the constant
`YII_DEBUG`
is defined as
`true`
in
`index.php`
. Debug mode is useful during
development stage, but it would impact performance because some components
cause extra burden in debug mode. For example, the message logger may record
additional debug information for every message being logged.
`YII_DEBUG`
is defined as
`true`
in
`index.php`
so to disable debug the following
should be in your
`index.php`
:
```
php
defined
(
'YII_DEBUG'
)
or
define
(
'YII_DEBUG'
,
false
);
```
Debug mode is very useful during development stage, but it would impact performance
because some components cause extra burden in debug mode. For example, the message
logger may record additional debug information for every message being logged.
### Enabling PHP opcode cache
Enabling the PHP opcode cache improves any PHP application performance and lowers
memory usage. Yii is no exception. It was tested with APC extension that caches
memory usage significantly. Yii is no exception. It was tested with
[
APC PHP extension
](
http://php.net/manual/en/book.apc.php
)
that caches
and optimizes PHP intermediate code and avoids the time spent in parsing PHP
scripts for every incoming request.
...
...
@@ -34,28 +41,69 @@ to save the time of parsing database schema. This can be done by setting the
`protected/config/main.php`
:
```
php
return
array
(
// ...
'components'
=>
array
(
// ...
'db'
=>
array
(
'class'
=>
'yii\db\Connection'
,
'dsn'
=>
'mysql:host=localhost;dbname=mydatabase'
,
'username'
=>
'root'
,
'password'
=>
''
,
'enableSchemaCache'
=>
true
,
// Duration of schema cache.
// 'schemaCacheDuration' => 3600,
// Name of the cache component used. Default is 'cache'.
//'schemaCache' => 'cache',
),
'cache'
=>
array
(
'class'
=>
'yii\caching\FileCache'
,
),
),
);
```
Note that
`cache`
application component should be configured.
### Combining and Minimizing Assets
TBD
### Using better storage for sessions
By default PHP uses
plain
files to handle sessions. It is OK for development and
By default PHP uses files to handle sessions. It is OK for development and
small projects but when it comes to handling concurrent requests it's better to
switch to another storage such as database. You can do so by configuring your
application via
`protected/config/main.php`
:
```
php
return
array
(
// ...
'components'
=>
array
(
'session'
=>
array
(
'class'
=>
'yii\web\DbSession'
,
// Set the following if want to use DB component other than
// default 'db'.
// 'db' => 'mydb',
// To override default session table set the following
// 'sessionTable' => 'my_session',
),
),
);
```
You can use
`CacheSession`
to store sessions using cache. Note that some
cache storages such as memcached has no guaranteee that session data will not
be lost leading to unexpected logouts.
Improving application
---------------------
### Using Caching Techniques
### Using
Serverside
Caching Techniques
As described in the Caching section, Yii provides several caching solutions that
may improve the performance of a Web application significantly. If the generation
...
...
@@ -66,6 +114,10 @@ If a whole page remains relative static, we can use the page caching approach to
save the rendering cost for the whole page.
### Leveraging HTTP to save procesing time and bandwidth
TBD
### Database Optimization
Fetching data from database is often the main performance bottleneck in
...
...
@@ -91,10 +143,20 @@ overwhelming data from database and exhausting the memory allocated to PHP.
### Using asArray
A good way to save memory and processing time on read-only pages is to use
ActiveRecord's
`asArray`
method.
```php
```
TBD
### Processing data in background
In order to respond to user requests faster you can process heavy parts of the
request later if there's no need for immediate response.
-
Cron jobs + console.
-
queues + handlers.
\ No newline at end of file
-
queues + handlers.
TBD
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment