Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quickest ways to speed up your YII application?

I've just started using YII and managed to finish my first app. unfortunately, launch day is close and I want this app to be super fast. So far, the only way of speeding it up I've come across, is standard caching. What other ways are there to speed up my app?

like image 895
coderama Avatar asked Dec 03 '12 07:12

coderama


3 Answers

First of all, read Performance Tuning in the official guide. Additionally:

  • Check HTTP caching.
  • Update your PHP. Each major version gives you a good boost.
  • Use redis (or at least database) for sessions (default PHP sessions are using files and are blocking).
  • Consider using nginx instead (or with) apache. It serves content much better.
  • Consider using CDN.
  • Tweak your database.

These are all general things that are relatively easy to do. If it's not acceptable afterwards, do not assume. Profile.

like image 96
Sam Dark Avatar answered Nov 18 '22 16:11

Sam Dark


1. Following best practices

In this recipe, we will see how to configure Yii for best performances and will see some additional principles of building responsive applications. These principles are both general and Yii-related. Therefore, we will be able to apply some of these even without using Yii.

Getting ready

Install APC (http://www.php.net/manual/en/apc.installation.php)

Generate a fresh Yii application using yiic webapp

2.Speeding up sessions 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 a common session storage for both servers

Default PHP sessions use files, so the maximum performance possible is limited by disk I/O

3.Using cache dependencies and chains

Yii supports many cache backends, but what really makes Yii cache flexible is the dependency and dependency chaining support. There are situations when you cannot just simply cache data for an hour because the information cached can be changed at any time.

In this recipe, we will see how to cache a whole page and still always get fresh data when it is updated. The page will be dashboard-type and will show five latest articles added and a total calculated for an account. Note that an operation cannot be edited as it was added, but an article can.

4.Profiling an application with Yii

If all of the best practices for deploying a Yii application are applied and you still do not have the performance you want, then most probably, there are some bottlenecks with the application itself. The main principle while dealing with these bottlenecks is that you should never assume anything and always test and profile the code before trying to optimize it.

like image 2
shivaP Avatar answered Nov 18 '22 15:11

shivaP


If most of your app is cacheable you should try a proxy like varnish.

like image 1
timg Avatar answered Nov 18 '22 16:11

timg