Commit b454d0ea by Nobuo Kihara

docs/guide/tutorial-performance-tuning.md better wordings[ci skip]

parent f638f429
...@@ -14,7 +14,7 @@ Preparing environment ...@@ -14,7 +14,7 @@ Preparing environment
A well configured environment to run PHP application really matters. In order to get maximum performance: A well configured environment to run PHP application really matters. In order to get maximum performance:
- Always use latest stable PHP version. Each major release brings significant performance improvements and reduced - Always use the latest stable PHP version. Each major release brings significant performance improvements and reduced
memory usage. memory usage.
- Use [APC](http://ru2.php.net/apc) for PHP 5.4 and less or [Opcache](http://php.net/opcache) for PHP 5.5 and more. It - Use [APC](http://ru2.php.net/apc) for PHP 5.4 and less or [Opcache](http://php.net/opcache) for PHP 5.5 and more. It
gives a very good performance boost. gives a very good performance boost.
...@@ -26,8 +26,8 @@ Preparing framework for production ...@@ -26,8 +26,8 @@ Preparing framework for production
First thing you should do before deploying your application to production environment 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 is to disable debug mode. A Yii application runs in debug mode if the constant
`YII_DEBUG` is defined as `true` in `index.php` so to disable debug the following `YII_DEBUG` is defined as `true` in `index.php`.
should be in your `index.php`: So, in order to disable debug mode, the following should be in your `index.php`:
```php ```php
defined('YII_DEBUG') or define('YII_DEBUG', false); defined('YII_DEBUG') or define('YII_DEBUG', false);
...@@ -43,7 +43,7 @@ Enabling the PHP opcode cache improves any PHP application performance and lower ...@@ -43,7 +43,7 @@ Enabling the PHP opcode cache improves any PHP application performance and lower
memory usage significantly. Yii is no exception. It was tested with both 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 [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 [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 optimize PHP intermediate code and avoid the time spent in parsing PHP
scripts for every incoming request. scripts for every incoming request.
### Turning on ActiveRecord database schema caching ### Turning on ActiveRecord database schema caching
...@@ -90,7 +90,7 @@ In order to learn how it can be achieved, refer to [assets](structure-assets.md) ...@@ -90,7 +90,7 @@ In order to learn how it can be achieved, refer to [assets](structure-assets.md)
### Using better storage for sessions ### Using better storage for sessions
By default PHP uses 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 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 switch to another storage such as database. You can do so by configuring your
application via `config/web.php`: application via `config/web.php`:
...@@ -101,11 +101,11 @@ return [ ...@@ -101,11 +101,11 @@ return [
'session' => [ 'session' => [
'class' => 'yii\web\DbSession', 'class' => 'yii\web\DbSession',
// Set the following if want to use DB component other than // Set the following if you want to use DB component other than
// default 'db'. // default 'db'.
// 'db' => 'mydb', // 'db' => 'mydb',
// To override default session table set the following // To override default session table, set the following
// 'sessionTable' => 'my_session', // 'sessionTable' => 'my_session',
], ],
], ],
...@@ -114,7 +114,7 @@ return [ ...@@ -114,7 +114,7 @@ return [
You can use `CacheSession` to store sessions using cache. Note that some You can use `CacheSession` to store sessions using cache. Note that some
cache storage such as memcached has no guarantee that session data will not cache storage such as memcached has no guarantee that session data will not
be lost leading to unexpected logouts. be lost, and it would lead to unexpected logouts.
If you have [Redis](http://redis.io/) on your server, it's highly recommended as session storage. If you have [Redis](http://redis.io/) on your server, it's highly recommended as session storage.
...@@ -132,7 +132,7 @@ If a whole page remains relative static, we can use the page caching approach to ...@@ -132,7 +132,7 @@ If a whole page remains relative static, we can use the page caching approach to
save the rendering cost for the whole page. save the rendering cost for the whole page.
### Leveraging HTTP to save processing time and bandwidth ### Leveraging HTTP caching to save processing time and bandwidth
Leveraging HTTP caching saves both processing time, bandwidth and resources significantly. It can be implemented by 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 sending either `ETag` or `Last-Modified` header in your application response. If browser is implemented according to
...@@ -211,7 +211,7 @@ In the view you should access fields of each individual record from `$posts` as ...@@ -211,7 +211,7 @@ In the view you should access fields of each individual record from `$posts` as
```php ```php
foreach ($posts as $post) { foreach ($posts as $post) {
echo $post['title']."<br>"; echo $post['title'] . "<br>";
} }
``` ```
...@@ -225,12 +225,12 @@ request later if there's no need for immediate response. ...@@ -225,12 +225,12 @@ request later if there's no need for immediate response.
There are two common ways to achieve it: cron job processing and specialized queues. There are two common ways to achieve it: cron job processing and specialized queues.
In the first case we need to save data which processing we want to do later to persistent storage In the first case we need to save the data that we want to process later to a persistent storage
such as database. A [console command](tutorial-console.md) that is run regularly via cron job queries such as database. A [console command](tutorial-console.md) that is run regularly via cron job queries
database and processes data if there's any. database and processes data if there's any.
The solution is OK for most cases but has one significant drawback. We aren't aware if there's data to The solution is OK for most cases but has one significant drawback. We aren't aware if there's data to
process before we query database so we're either querying database quite often or have a slight delay process before we query database, so we're either querying database quite often or have a slight delay
between each data processing. between each data processing.
This issue could be solved by queue and job servers such RabbitMQ, ActiveMQ, Amazon SQS and more. This issue could be solved by queue and job servers such RabbitMQ, ActiveMQ, Amazon SQS and more.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment