Browse Source

Clean workerman code (#6104)

* Clean workerman code

* Clean Kumbia raw to rerun travis
Joan Miquel 4 years ago
parent
commit
a5941aa780

+ 1 - 1
frameworks/PHP/kumbiaphp/bench/app/controllers/ra_controller.php

@@ -44,7 +44,7 @@ class RaController extends AppController
             $id = mt_rand(1, 10000);
 
             $sth->execute([$id]);
-            $row = ['id' => $id, 'randomNumber' => $sth->fetchColumn()];
+            $row = $sth->fetch(PDO::FETCH_ASSOC);
             $updateStatement->execute(
                 [$row['randomNumber'] = mt_rand(1, 10000), $id]
             );

+ 15 - 16
frameworks/PHP/workerman/app.php

@@ -4,16 +4,15 @@ use Workerman\Protocols\Http\Request;
 
 function init()
 {
-    global $statement, $fortune, $random, $update;
+    global $world, $fortune, $update;
     $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world',
         'benchmarkdbuser', 'benchmarkdbpass',
         [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
         PDO::ATTR_EMULATE_PREPARES    => false]
     );
-    $statement = $pdo->prepare('SELECT id,randomNumber FROM World WHERE id=?');
-    $fortune   = $pdo->prepare('SELECT id,message FROM Fortune');
-    $random    = $pdo->prepare('SELECT id,randomNumber FROM World WHERE id=?');
-    $update    = $pdo->prepare('UPDATE World SET randomNumber=? WHERE id=?');
+    $world   = $pdo->prepare('SELECT id,randomNumber FROM World WHERE id=?');
+    $fortune = $pdo->prepare('SELECT id,message FROM Fortune');
+    $update  = $pdo->prepare('UPDATE World SET randomNumber=? WHERE id=?');
 }
 
 function router(Request $request)
@@ -56,19 +55,19 @@ function router(Request $request)
 
 function db()
 {
-    global $statement;
+    global $world;
 
-    $statement->execute([mt_rand(1, 10000)]);
+    $world->execute([mt_rand(1, 10000)]);
 
     return new Response(200, [
         'Content-Type' => 'application/json',
         'Date'         => Header::$date
-    ], json_encode($statement->fetch()));
+    ], json_encode($world->fetch()));
 }
 
 function query($request)
 {
-    global $statement;
+    global $world;
 
     $query_count = 1;
     $q = $request->get('q');
@@ -77,8 +76,8 @@ function query($request)
     }
 
     while ($query_count--) {
-        $statement->execute([mt_rand(1, 10000)]);
-        $arr[] = $statement->fetch();
+        $world->execute([mt_rand(1, 10000)]);
+        $arr[] = $world->fetch();
     }
 
     return new Response(200, [
@@ -89,7 +88,7 @@ function query($request)
 
 function updateraw($request)
 {
-    global $random, $update;
+    global $world, $update;
 
     $query_count = 1;
     $q = $request->get('q');
@@ -99,13 +98,13 @@ function updateraw($request)
 
     while ($query_count--) {
         $id = mt_rand(1, 10000);
-        $random->execute([$id]);
-        $world = ['id' => $id, 'randomNumber' => $random->fetchColumn()];
+        $world->execute([$id]);
+        $item = $world->fetch();
         $update->execute(
-            [$world['randomNumber'] = mt_rand(1, 10000), $id]
+            [$item['randomNumber'] = mt_rand(1, 10000), $id]
         );
 
-        $arr[] = $world;
+        $arr[] = $item;
     }
 
     // $pdo->beginTransaction();