Browse Source

Fix typo benchmark_config

Natchanon Tatsaneepong 11 years ago
parent
commit
b5f8dc0d01
2 changed files with 30 additions and 7 deletions
  1. 29 6
      php-yii2/app/controllers/SiteController.php
  2. 1 1
      php-yii2/benchmark_config

+ 29 - 6
php-yii2/app/controllers/SiteController.php

@@ -3,6 +3,7 @@
 namespace app\controllers;
 
 use Yii;
+use yii\helpers\Html;
 use yii\web\Controller;
 
 class SiteController extends Controller
@@ -29,7 +30,7 @@ class SiteController extends Controller
             $arr = $statement->bindValue(':id',mt_rand(1, 10000))->queryOne();
         } else {
             if ($queries > 500) $queries = 500;
-            elseif ($queries < 0 ) $queries = 1;
+            elseif ($queries <= 0 ) $queries = 1;
             // Create an array with the response string.
             $arr = array();
             // For each query, store the result set values in the response array
@@ -43,8 +44,30 @@ class SiteController extends Controller
     }
 
     public function actionFortunes() {
+        // Test Data
+//        $arr = [
+//            11=>'<script>alert("This should not be displayed in a browser alert box");</script>',
+//            4=>'A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1',
+//            5=>'A computer program does what you tell it to do, not what you want it to do.',
+//            2=>'A computer scientist is someone who fixes things that aren\'t broken.',
+//            8=>'A list is only as strong as its weakest link. — Donald Knuth',
+//            //0=>'Additional fortune added at request time.',
+//            //0=>'Additional fortune added at request time.',
+//            3=>'After enough decimal places, nobody gives a damn.',
+//            7=>'Any program that runs right is obsolete.',
+//            10=>'Computers make very fast, very accurate mistakes.',
+//            6=>'Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen',
+//            9=>'Feature: A bug with seniority.',
+//            1=>'fortune: No such file or directory',
+//            12=>'フレームワークのベンチマーク'
+//        ];
+//        foreach($arr as $k=>$v) {
+//            Yii::$app->db->createCommand('insert into Fortune (id,message) values (:id,:message)',[':id'=>$k,':message'=>$v])->execute();
+//        }
+
+
         $arr = Yii::$app->db->createCommand('select id, message from Fortune')->queryAll();
-        $arr[0] = 'Additional fortune added at request time.';
+        $arr[] = ['id'=>0,'message'=>'Additional fortune added at request time.'];
         asort($arr);
         header("Content-Type: text/html; charset=utf-8");
         echo <<<EOM
@@ -60,10 +83,10 @@ class SiteController extends Controller
             <th>message</th>
             </tr>
 EOM;
-        foreach ( $arr as $id => $fortune ) {
+        foreach ( $arr as $val ) {
             echo '<tr>';
-            echo '<td>'.$id.'</td>';
-            echo '<td>'.htmlspecialchars($fortune, ENT_QUOTES, 'utf-8').'</td>';
+            echo '<td>'.$val['id'].'</td>';
+            echo '<td>'.Html::encode($val['message']).'</td>';
             echo '</tr>';
         }
         echo <<<EOM
@@ -76,7 +99,7 @@ EOM;
 
     public function actionUpdates($queries = 1) {
         if ($queries > 500) $queries = 500;
-        elseif ($queries < 0 ) $queries = 1;
+        elseif ($queries <= 0 ) $queries = 1;
         $selectCommand = Yii::$app->db->createCommand('select randomNumber from World where id = :id');
         $updateCommand = Yii::$app->db->createCommand('update World set randomNumber = :num where id = :id');
         $arr = [];

+ 1 - 1
php-yii2/benchmark_config

@@ -7,7 +7,7 @@
       "db_url": "/site/db",
       "query_url": "/site/db?queries=",
       "fortune_url": "/site/fortunes",
-      "update_url": "/site/update?queries=",
+      "update_url": "/site/updates?queries=",
       "port": 8080,
       "approach": "Realistic",
       "classification": "Fullstack",