Browse Source

Change workerman mysqli (#5177)

* Delete persistent db connection
and use more workers

* Add info in comments

* Update info in comment
Joan Miquel 5 years ago
parent
commit
e0abb1bfac

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

@@ -42,7 +42,7 @@ $http_worker->onMessage = static function ($connection) {
             return;
 
         case '/fortune':
-            //Http::header('Content-Type: text/html; charset=utf-8');
+            // By default use 'Content-Type: text/html; charset=utf-8';
             $mysql->query('SELECT id,message FROM Fortune', 
                 static function ($command) use ($connection) {
                     $arr = $command->resultRows;

+ 4 - 4
frameworks/PHP/workerman/server-mysqli.php

@@ -6,10 +6,10 @@ use Workerman\Protocols\Http;
 use Workerman\Worker;
 
 $http_worker                = new Worker('http://0.0.0.0:8080');
-$http_worker->count         = shell_exec('nproc');
-$http_worker->onWorkerStart = function () {
+$http_worker->count         = shell_exec('nproc') * 3;
+$http_worker->onWorkerStart = static function () {
     global $db;
-    $db = new mysqli('p:tfb-database', 'benchmarkdbuser', 'benchmarkdbpass', 'hello_world');
+    $db = new mysqli('tfb-database', 'benchmarkdbuser', 'benchmarkdbpass', 'hello_world');
 };
 
 $http_worker->onMessage = static function ($connection) {
@@ -23,7 +23,7 @@ $http_worker->onMessage = static function ($connection) {
             return $connection->send(db());
 
         case '/fortune':
-            //Http::header('Content-Type: text/html; charset=utf-8');
+            // by default use 'Content-Type: text/html; charset=utf-8';
             return $connection->send(fortune());
 
         case '/update':

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

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