Yii preformance

I’m a veteran php coder and this days I received an offer to a totally high traffic web site it’s a bottleneck on choosing among a dozen of frameworks stands over there and making mistakes takes a big price for me so I wanna to ask you about the reality in this area not just some damned motto which is there choosing a framework for such a high traffic web site reasonable and is there Yii the best one or not? founding a good answer about this simple/hard question sounds too hard!

Did you read this?

About Yii

Yap I read it before but an old Persian expression say “a dairy never say it’s yogurt is sour!” when you see some exaltation it’s a bit hard to believe all of them is true. I need some practical tests not just a hello word benchmarking actually it says nothing about the performance if you really want to compare you should write hole a project with two different framework and then running your benchmarking.


Using a framework always comes with a tradeoff compared to “pure” PHP. That’s the price you have to pay, but you get better organized code and have ready-to-use solutions for common web app problems. Still i recommend you to give Yii a try: It tries to stay very slim and only loads what’s really required for handling a request. You can make it stay out of the way if you want to handle some specific action solely with your custom code.

So if you’re like me and like the freedom to do whatever you want in PHP but still having the option to use prepared components (which are coded mostly excellent btw.), Yii is perfect for you.

Well, when you look for something with "high" performance, Yii is something to check out. But first you should look on "development" speed. And not only on framework speed.

Things you should checkout or think about:

a ) Is it possible to write C(++) code and use it in the framework

B ) How quick could I write plugins, extension? (For example RoR is a pain imho)

c ) How good is the cache management and usage? Is it easy to extend? Modify? Test? And how fast is it?

I could not help on a) cause I dont wrote any C++ code for yii -_- but:

B ) Yii is one of the best,if not THE best framework to extend. I dont found any framework so far with such a good API, API hooks and events, as Yii

c ) Yii has a quit impressive cache management system, cause it loads just "what" is needed and is easy to extend ot change (even the cache backend)

Well, another good framework is Grails, its amazingly close to RoR, but i compiles to Java, which gives some extra boost (Not as fast as pure java code) but its close to it.

Well, if you want to check out new "ways" you should checkout LUA, if you are in a "geeky" mood, or even the lisp webframework (forgot its name)

Thanks a lot for your technical and logical replay. fortunately :) I have no choice except PHP.

I have a really good support on Server for unlimited cache services but my agreement with client is based on the best performance as possible to reduce the price of servers and so on.

my client suggest to run some practical tests to get in hand a real benchmarking on Framework vs. PHP hard code to deal with this bottleneck. anyway I do my best to reduce database size and fully implementation of any kind of cache services. and I release the result here to be a good source for whom faced with this question and situation. and I think it cost to test Yii on a practical high traffic web site.

What was the old spell:

So should it be written, so should it be done? :)

If you really need the best speed, you must write your own code. And you will end on a "micro" framework. Something like fatfree or mimvic. Which just adds MVC to your code (or it will be horrible to extend and modify) and add a database layer to it which makes some common database calls, like getting and checking user logins.

At sum it is something like:

Maintainable <-> Speed comparison of code.

Another things you could checkout are other PHP server programs, for example nginx or cherokee. But they have a drawback compared to apache. Apache integrates PHP on load, while the rest runs over fcgi. This means a new instance on every call. But on static pages this dosnt matter but on hundreds of servers… But this will be fixed in a future version of php which will integrates a new way for fcgi calls, and handling. If you have time until this version of php will be released, it is something to wait for :)

Dear all I told you I’m trying to run more practical test on yii to show what is the gap between it’s performance with other frameworks and raw php here is the result. my test server was a Windows7 Home Premium machine with intel corei7 1.6GHz up to 2.8GHz CPU and 4GB DDR3 RAM running XAMPP with PHP 5.3.1, Apache 2.2.14, MySQL 5.1.41

database has been generated bycode below.



 * @author phpveteran

 * @copyright 2010


/* Connecting, selecting database  */

$db_link = mysql_connect("localhost", "root", "ringsport");

if (!$db_link) {

   die("Could not connect: " . mysql_error());


mysql_select_db("benchmarking") or die("Could not select database");


/* Performing SQL query */






	while (strlen($rand_text)<251)


	$query = "INSERT INTO `benchmarking`.`text_var` (

				`id` ,

				`random_var` ,


			)VALUES (

				NULL , '$rand_text', '$rand_text');";



/* Closing connection */



Raw PHP:



 * @author phpveteran

 * @copyright 2010


/* Connecting, selecting database  */

$db_link = mysql_connect("localhost", "root", "ringsport");

if (!$db_link) {

   die("Could not connect: " . mysql_error());


mysql_select_db("benchmarking") or die("Could not select database");


/* Performing SQL query */

$query = "SELECT * FROM `text_var` WHERE `random_var` = '6CEM3cjkRSg8gLgDSMSyQHwSCeNaPrRhKPMFShQYSFygqZhwY4NWpweEENCSxMghMqfOB9K2tQ6kNCfEnqtaSTMMKdnEhwfQfKnsnBQr2ZATE1ARcKLbfT417tpHDQ4hPe3jScMZHZEpLpn8sMs8QDPSyWkQNjWqqCLGtn3sAkKD1fSbk14TamcKEHn5c2txDEEaswwtQKLfQKgmfXEp3nwq8HMNYxTSkDSY3ZBRMhKNb55H1tM2zcG8Za'";

$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result)) {



/* Closing connection */



Yii clean and fresh setup SiteController.php and actionIndex

public function actionIndex()


		// renders the view file 'protected/views/site/index.php'

		// using the default layout 'protected/views/layouts/main.php'


		$connection=new CDbConnection('mysql:host=localhost;dbname=benchmarking','root','ringsport');


		$dataReader = $connection->createCommand("SELECT * FROM `text_var` WHERE `random_var` = '6CEM3cjkRSg8gLgDSMSyQHwSCeNaPrRhKPMFShQYSFygqZhwY4NWpweEENCSxMghMqfOB9K2tQ6kNCfEnqtaSTMMKdnEhwfQfKnsnBQr2ZATE1ARcKLbfT417tpHDQ4hPe3jScMZHZEpLpn8sMs8QDPSyWkQNjWqqCLGtn3sAkKD1fSbk14TamcKEHn5c2txDEEaswwtQKLfQKgmfXEp3nwq8HMNYxTSkDSY3ZBRMhKNb55H1tM2zcG8Za'")->query();






Zend framework fresh and clean IndexController.php indexAction

public function indexAction()


        // action body


		require_once 'Zend/Db.php';

		$db = Zend_Db::factory('Mysqli',


					'host' => 'localhost',

					'dbname' => 'benchmarking',

					'username'=> 'root',

					'password' => 'ringsport')


		$stmt = $db->query("SELECT * FROM `text_var` WHERE `random_var` = '6CEM3cjkRSg8gLgDSMSyQHwSCeNaPrRhKPMFShQYSFygqZhwY4NWpweEENCSxMghMqfOB9K2tQ6kNCfEnqtaSTMMKdnEhwfQfKnsnBQr2ZATE1ARcKLbfT417tpHDQ4hPe3jScMZHZEpLpn8sMs8QDPSyWkQNjWqqCLGtn3sAkKD1fSbk14TamcKEHn5c2txDEEaswwtQKLfQKgmfXEp3nwq8HMNYxTSkDSY3ZBRMhKNb55H1tM2zcG8Za'");


		while ($data = $stmt->fetchAll()) {






now bench marking result:

Raw PHP:

C:\xampp\apache\bin>ab -t 20 -c 4 http://localhost/random_text/index.php

Benchmarking localhost (be patient)

Finished 125 requests

Concurrency Level:      4

Time taken for tests:   20.585 seconds

Complete requests:      125

Failed requests:        0

Write errors:           0

Total transferred:      155575 bytes

HTML transferred:       117856 bytes

Requests per second:    6.07 [#/sec] (mean)

Time per request:       658.726 [ms] (mean)

Time per request:       164.681 [ms] (mean, across all concurrent requests)

Transfer rate:          7.38 [Kbytes/sec] received

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    0   0.4      0       1

Processing:   596  642  58.2    632     878

Waiting:      596  642  58.1    631     877

Total:        596  643  58.2    632     878

Percentage of the requests served within a certain time (ms)

  50%    632

  66%    634

  75%    654

  80%    678

  90%    711

  95%    745

  98%    877

  99%    878

 100%    878 (longest request)

Yii Framework

C:\xampp\apache\bin>ab -t 20 -c 4 http://yii.local/index.php

Benchmarking yii.local (be patient)

Finished 109 requests

Concurrency Level:      4

Time taken for tests:   20.322 seconds

Complete requests:      109

Failed requests:        0

Write errors:           0

Total transferred:      133525 bytes

HTML transferred:       101152 bytes

Requests per second:    5.36 [#/sec] (mean)

Time per request:       745.767 [ms] (mean)

Time per request:       186.442 [ms] (mean, across all concurrent requests)

Transfer rate:          6.42 [Kbytes/sec] received

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    0   0.4      0       1

Processing:   630  728 104.4    709    1047

Waiting:      630  727 104.3    709    1047

Total:        630  728 104.4    709    1047

Percentage of the requests served within a certain time (ms)

  50%    708

  66%    730

  75%    777

  80%    822

  90%    888

  95%    955

  98%   1047

  99%   1047

 100%   1047 (longest request)

Zend Framework

C:\xampp\apache\bin>ab -t 20 -c 4 http://zf.local/index.php

Benchmarking zf.local (be patient)

Finished 49 requests

Concurrency Level:      4

Time taken for tests:   20.722 seconds

Complete requests:      49

Failed requests:        0

Write errors:           0

Total transferred:      64821 bytes

HTML transferred:       49674 bytes

Requests per second:    2.36 [#/sec] (mean)

Time per request:       1691.607 [ms] (mean)

Time per request:       422.902 [ms] (mean, across all concurrent requests)

Transfer rate:          3.05 [Kbytes/sec] received

Connection Times (ms)

              min  mean[+/-sd] median   max

Connect:        0    0   0.3      0       1

Processing:  1299 1608 230.1   1599    2091

Waiting:     1298 1607 230.0   1598    2089

Total:       1299 1608 230.1   1600    2091

Percentage of the requests served within a certain time (ms)

  50%   1534

  66%   1679

  75%   1733

  80%   1754

  90%   1910

  95%   2090

  98%   2091

  99%   2091

 100%   2091 (longest request)

check this test http://www.yiiframework.com/performance/ and this

http://symfony-reloaded.org/fastso you can see that yii have a nice performance.

maybe symfony 2.0 is faster but anywhere symfony 2.0 is still under development.

in this test http://www.yiiframework.com/performance/ i cant believe that

prado is faster then symfony

here is something I should mention symfony benchmarking seems fishy and comparison is not fare enough to make a decision. it’s because symfony used router cache by default that can have a serious bottleneck on high request for any other frameworks I totally refuse any benchmarking on just running the damn hello word! it shows nothing

what do you think about the symfony test ?

http://symfony-reloaded.org/fast there is a product application test as well

This topic was discussed many times!!!

The fact is that every framework will say: “I’m the faster”, or “I’m in the fastest framewroks”

This doesn’t matter…


If the only concern for you to chose one framwork over another is if it is "the fastest", then compare those frameworks yourself with test that are good for you and choose based on these tests!

As already somebody in this forum says, a framework in not only how fast it is, but how simplifies your life in every aspect of programing cicle!

if you read through the the treat you will see I asked this for a very special project that should handle high traffic and concurrent users. reasons to choose one framework among the others is not distinguished as you think over there we have a dozen of really good frameworks cack/zend/yii/symfony and so on all of them have a very good architecture, design, documents, forum and so on. so if you want to choose one you should focus on some details like performance / security and something that people like you always said WE DO NOT CHOOSE FRAMEWORKS ONLY FOR PERFORMANCE! yup dude it’s deal we should choose frameworks only for some details because all of them are good

So, because of this:

, you fall in this:

Then, DO your own test… and choose bases on these tests…

Don’t ask in yii’s forum “is yii the best one?” (all here will say “Yes for me”)… the same (i think) will happen y you ask in symphony forum “Is symphony the best?” (all of them will say “Yes for me”)

So the final desicion is up to you…

You will not rest easy until you do your own tests and see the results…