Speeding up session handling
Native session handling in PHP is fine in most cases. There are at least two possible reasons why you will want to change the way sessions are handled:
- When using multiple servers, you need to have common session storage for both servers.
- Default PHP sessions use files, so the maximum performance possible is limited by disk I/O.
- Default PHP sessions are blocking concurrent session storages. In this recipe, we will see how to use efficient storage for Yii sessions.
Getting ready
Create a new yii2-app-basic
application using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html, and install the Memcache server and the memcache
PHP extension.
Get Yii2 Application Development Cookbook - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.