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
97a5a9d4
Commit
97a5a9d4
authored
Nov 29, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More docs on performance
parent
1a7ce04b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
6 deletions
+41
-6
performance.md
docs/guide/performance.md
+41
-6
No files found.
docs/guide/performance.md
View file @
97a5a9d4
...
...
@@ -28,9 +28,10 @@ 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 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
memory usage significantly. Yii is no exception. It was tested with both
[
PHP 5.5 OPcache
](
http://php.net/manual/en/book.opcache.php
)
and
[
APC PHP extension
](
http://php.net/manual/en/book.apc.php
)
. Both cache
and optimize PHP intermediate code and avoid the time spent in parsing PHP
scripts for every incoming request.
### Turning on ActiveRecord database schema caching
...
...
@@ -69,7 +70,10 @@ Note that `cache` application component should be configured.
### Combining and Minimizing Assets
TBD
It is possible to combine and minimize assets, typically JavaScript and CSS, in order to slightly improve page load
time and therefore deliver better experience for end user of your application.
In order to learn how it can be achieved, refer to
[
assets
](
assets.md
)
guide section.
### Using better storage for sessions
...
...
@@ -118,7 +122,38 @@ save the rendering cost for the whole page.
### Leveraging HTTP to save processing time and bandwidth
TBD
Leveraging HTTP caching saves both processing time, bandwidth and resources significantly. It can be implemented by
sending either
`ETag`
or
`Last-Modified`
header in your application response. If browser is implemented according to
HTTP specification (most browsers are), content will be fetched only if it is different from what it was prevously.
Forming proper headers is time consuming task so Yii provides a shortcut in form of controller filter
[
[\yii\web\HttpCache
]
]. Using it is very easy. In a controller you need to implement
`behaviors`
method like
the following:
```
php
public
function
behaviors
()
{
return
[
'httpCache'
=>
[
'class'
=>
\yii\web\HttpCache
::
className
(),
'only'
=>
[
'list'
],
'lastModified'
=>
function
(
$action
,
$params
)
{
$q
=
new
Query
();
return
strtotime
(
$q
->
from
(
'users'
)
->
max
(
'updated_timestamp'
));
},
// 'etagSeed' => function ($action, $params) {
// return // generate etag seed here
//}
],
];
}
```
In the code above one can use either
`etagSeed`
or
`lastModified`
. Implementing both isn't necessary. The goal is to
determine if content was modified in a way that is cheaper than fetching and rendering that content.
`lastModified`
should return unix timestamp of the last content modification while
`etagSeed`
should return a string that is then
used to generate
`ETag`
header value.
### Database Optimization
...
...
@@ -140,7 +175,7 @@ to create one or several objects to represent each row of query result. For data
intensive applications, using DAO or database APIs at lower level could be
a better choice.
Last but not least, use
LIMIT in your SELECT
queries. This avoids fetching
Last but not least, use
`LIMIT`
in your
`SELECT`
queries. This avoids fetching
overwhelming data from database and exhausting the memory allocated to PHP.
### Using asArray
...
...
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