Browse Source

Workerman separate single and multiple queries (#5206)

Joan Miquel 5 years ago
parent
commit
b91200fc63

+ 4 - 4
frameworks/PHP/workerman/benchmark_config.json

@@ -5,8 +5,8 @@
       "json_url": "/json",
       "plaintext_url": "/plaintext",
       "db_url": "/db",
-      "query_url": "/db?queries=",
-      "update_url": "/update?queries=",
+      "query_url": "/query?q=",
+      "update_url": "/update?q=",
       "fortune_url": "/fortune",
       "port": 8080,
       "approach": "Realistic",
@@ -26,8 +26,8 @@
     },
     "pgsql": {
       "db_url": "/db",
-      "query_url": "/db?queries=",
-      "update_url": "/update?queries=",
+      "query_url": "/query?q=",
+      "update_url": "/update?q=",
       "fortune_url": "/fortune",
       "port": 8080,
       "approach": "Realistic",

+ 10 - 9
frameworks/PHP/workerman/dbraw.php

@@ -1,18 +1,19 @@
 <?php
-function dbraw()
+function db()
 {
     global $statement;
 
-    //$statement = $pdo->prepare('SELECT id,randomNumber FROM World WHERE id=?');
-
-    if ( ! isset($_GET['queries'])) {
-        $statement->execute([mt_rand(1, 10000)]);
-        return json_encode($statement->fetch(), JSON_NUMERIC_CHECK);
-    }
+    $statement->execute([mt_rand(1, 10000)]);
+    return json_encode($statement->fetch(), JSON_NUMERIC_CHECK);
+}
 
+function query()
+{
+    global $statement;
+    
     $query_count = 1;
-    if ($_GET['queries'] > 1) {
-        $query_count = min($_GET['queries'], 500);
+    if ($_GET['q'] > 1) {
+        $query_count = min($_GET['q'], 500);
     }
 
     while ($query_count--) {

+ 5 - 1
frameworks/PHP/workerman/server.php

@@ -32,11 +32,15 @@ $http_worker->onMessage = static function ($connection) {
 
         case '/db':
             Http::header('Content-Type: application/json');
-            return $connection->send(dbraw());
+            return $connection->send(db());
 
         case '/fortune':
             // By default use 'Content-Type: text/html; charset=utf-8';
             return $connection->send(fortune());
+            
+        case '/query':
+            Http::header('Content-Type: application/json');
+            return $connection->send(query());
 
         case '/update':
             Http::header('Content-Type: application/json');

+ 2 - 2
frameworks/PHP/workerman/updateraw.php

@@ -3,8 +3,8 @@ function updateraw()
 {
     global $pdo;
     $query_count = 1;
-    if ($_GET['queries'] > 1) {
-        $query_count = min($_GET['queries'], 500);
+    if ($_GET['q'] > 1) {
+        $query_count = min($_GET['q'], 500);
     }
 
     $statement = $pdo->prepare('SELECT randomNumber FROM World WHERE id=?');