A simple statement in Yii make apache consume CPU 100%
Test Environment:
1032
CPU:Q9400(2.66 4Core)
OS: Windows server 2008(64)
PHP:5.2.14
Web Server:Apache2.0
No APC, YII:
Cache off, debug off, log off,
Test Method:
page a : testa.php,
<?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
<?php
function createPDOConnect()
{
$connection;
try{
$connection = new PDO("oci:dbname=192.168.1.13/ORCL;charset=AL32UTF8", 'WDM_APP', '1234');
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$connection->setAttribute(PDO::ATTR_TIMEOUT,60*60*10);
}catch(PDOException $e){
echo ("Error:".$e->getMessage()."<br>");
die();
}
return $connection;
}
$dbh = createPDOConnect();
$sql = "SELECT * FROM WEBSITE t WHERE ROWNUM<=10";
$stmt = $dbh->prepare( $sql );
$stmt->execute();
$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
SiteController.php
public function actionIndex()
{
$this->render('index');
}
index.php
<?php
$this->layout=false;
echo "Hello World!;
?>
1034
page d : testd.html a simple html page without yii
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Detail</title>
<link rel="stylesheet" type="text/css" href="/wm/css/info_en_us.css" />
</head>
<body>
1234567890
1234567890
1234567890
</body>
</html>
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?