Why does YII consume so much CPU via apache?

A simple statement in Yii make apache consume CPU 100%

Test Environment:



CPU:Q9400(2.66 4Core)

OS: Windows server 2008(64)


Web Server:Apache2.0


Cache off, debug off, log off,

Test Method:

page a : testa.php,


	for ($index = 0; $index < 10; $index++) {

		echo $index;


	echo "<br/>";

	for ($index = 0; $index < 30; $index++) {

		echo $index." ";


	echo "<br/>";

	for ($index = 0; $index < 50; $index++) {

		echo $index." ";


	echo "<br/>";

	echo time();


page b : testb.php, a simple page return data from database by PDO without yii


	function createPDOConnect()




			$connection = new PDO("oci:dbname=;charset=AL32UTF8", 'WDM_APP', '1234');

			$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

			$connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);


		}catch(PDOException $e){

			echo ("Error:".$e->getMessage()."<br>");



        return $connection;



	$dbh = createPDOConnect();



	$stmt = $dbh->prepare( $sql );


	$selectDataArray = $stmt->fetchAll(PDO::FETCH_ASSOC);

	echo count($selectDataArray);

	foreach($selectDataArray as $d){

		echo $d['WEBSITE_ID'];



page c : testc.php, a simple page return "Hello world" with yii


public function actionIndex()







	echo "Hello World!;




page d : testd.html a simple html page without yii

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<link rel="stylesheet" type="text/css" href="/wm/css/info_en_us.css" />








Client Thread Count: 100

Test Result:

test on page a, apache cpu 5%

test on page b, apache cpu 35%

test on page c, apache cpu 95%

test on page d, apache cpu 3%

I also test it on apache 2.2, the same result!

Why does YII consume so much CPU via apache?


@Antonio: thanks for sharing with us (again! :]) address to this wonderful post, as we are all (or most of us) still shocked of results that are shown there, but look into the code! Post author uses Oracle while you are pointing him to MySQL demonstration.

@climb: You are using Oracle! Oracle is deadly, ugly, stupidly ssssslow (at least in comparison to other RDBMS). I wouldn’t be surprised if your CPU load would not come from Yii but from Oracle. Even more - I would be surprised, if you would show up with some evidences that it is not coming from Oracle. Oracle is slooooow!

I’m using Oracle in my currently developed application and I must admit that I’m shocked! The very same code, byte by byte, executed with DB set to Oracle in some cases is working over one hundred times slower than in MySQL. Look at above comparison, results from my internal tests done last weekend:


Done selecting 300 records (160 columns) using AR! Execution time:  2,38169789314 secs. 

Done selecting 300 records (1 column) using AR! Execution time:  0,05867600441 secs. 


Done selecting 2300 records (160 columns) using AR! Execution time:  0,24194717407 secs. 

Done selecting 2300 records (1 column) using AR! Execution time:  0,16201305389 secs. 

It took ten times longer Oracle to select 300 records than MySQL to select nine times more records!

And I have Oracle installed on separate machine, not on the same as Apache, PHP and Yii. If you have it on the same, connecting via localhost I wouldn’t be surprised if Oracle would be your main cause for such processor load. Oracle is slow! At least for web or PHP and in comparison to other database systems!

Thanks everyone!The problems have been solved!

The reason is PDO_OCI Driver is unstable!

You are using PDO_OCI or OCI8 driver? I also heard (as it is stated on website) that this driver is unstable, experimental and many developers still advices to use old OCI8 even for 11+ Oracle databases. But my personal experience is, that it work a bit better than OCI8 and I would propose you to double check if it is truly driver problem or maybe somewhere between it and the server.

Edit: If you are interested in this topic, please continue in this Wiki article, where one of possible solutions (for speeding up ActiveRecord on Oracle) is presented.