Browse Source

Fix update in php-ngx and workerman (#5360)

* Fix update in php-ngx and workerman

* Workers x4
Joan Miquel 5 years ago
parent
commit
1ce4314d79

+ 8 - 6
frameworks/PHP/php-ngx/app.php

@@ -52,15 +52,17 @@ function update()
         $random->execute([$id]);
         $random->execute([$id]);
 
 
         $world = ['id' => $id, 'randomNumber' => $random->fetchColumn()];
         $world = ['id' => $id, 'randomNumber' => $random->fetchColumn()];
-        $world['randomNumber'] = mt_rand(1, 10000);
+        $update->execute(
+            [$world['randomNumber'] = mt_rand(1, 10000), $id]
+        );
         $arr[] = $world;
         $arr[] = $world;
     }
     }
 
 
-    $pdo->beginTransaction();
-    foreach($arr as $world) {
-        $update->execute([$world['randomNumber'], $world['id']]);
-    }
-    $pdo->commit();
+    // $pdo->beginTransaction();
+    // foreach($arr as $world) {
+    //     $update->execute([$world['randomNumber'], $world['id']]);
+    // }
+    // $pdo->commit();
 
 
     echo json_encode($arr, JSON_NUMERIC_CHECK);
     echo json_encode($arr, JSON_NUMERIC_CHECK);
 }
 }

+ 8 - 6
frameworks/PHP/workerman/app.php

@@ -36,16 +36,18 @@ function updateraw()
         $id = mt_rand(1, 10000);
         $id = mt_rand(1, 10000);
         $random->execute([$id]);
         $random->execute([$id]);
         $world = ['id' => $id, 'randomNumber' => $random->fetchColumn()];
         $world = ['id' => $id, 'randomNumber' => $random->fetchColumn()];
-        $world['randomNumber'] = mt_rand(1, 10000);
+        $update->execute(
+            [$world['randomNumber'] = mt_rand(1, 10000), $id]
+        );
 
 
         $arr[] = $world;
         $arr[] = $world;
     }
     }
     
     
-    $pdo->beginTransaction();
-    foreach($arr as $world) {
-        $update->execute([$world['randomNumber'], $world['id']]);
-    }
-    $pdo->commit();
+    // $pdo->beginTransaction();
+    // foreach($arr as $world) {
+    //     $update->execute([$world['randomNumber'], $world['id']]);
+    // }
+    // $pdo->commit();
 
 
     return json_encode($arr, JSON_NUMERIC_CHECK);
     return json_encode($arr, JSON_NUMERIC_CHECK);
 }
 }

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

@@ -6,7 +6,7 @@ use Workerman\Protocols\Http;
 use Workerman\Worker;
 use Workerman\Worker;
 
 
 $http_worker                = new Worker('http://0.0.0.0:8080');
 $http_worker                = new Worker('http://0.0.0.0:8080');
-$http_worker->count         = (int) shell_exec('nproc') * 3;
+$http_worker->count         = (int) shell_exec('nproc') * 4;
 $http_worker->onWorkerStart = function () {
 $http_worker->onWorkerStart = function () {
     global $pdo, $statement, $fortune, $random, $update;
     global $pdo, $statement, $fortune, $random, $update;
     $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world',
     $pdo = new PDO('mysql:host=tfb-database;dbname=hello_world',