-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The server to receive data after a number of database connections will become more, eventually leading to error. #187
Comments
Creating mysql connections without closing them can cause this $worker = new Worker(...);
// Global db connection.
$db_connection = null;
$worker->onWorkerStart = function($worker) {
// Create global db connection.
global $db_connection;
$db_connection = new your\db\Connection(....);
};
$worker->onMessage = function($client_connection, $data) {
// Reuse global db connection.
global $db_connection;
$db->connection->query(....);
}; |
ok,i'll try it. |
Is not the database can not use tp5? |
$worker = new Worker(...);
// Global db connection.
$db_connection = null;
$db_configs = [
"host" => "localhost",
"user" => "root",
"dbtable" => "test",
"password" => "123456!@#",
"charset" => "",
];
$worker->onWorkerStart = function($worker) {
// Create global db connection.
global $db_connection, $db_configs;
require_once your_path . "/think/db/connector/mysql.php";
// $db_connection = new \think\db\connector\MySQL($db_configs);
$db_connection = Db::connect($db_configs);
};
$worker->onMessage = function($client_connection, $data) {
// Reuse global db connection.
global $db_connection ;
$result = $db_connection ->table('')->select();
file_put_contents("/tmp/tmp.log", var_export($result, true)."\n", FILE_APPEND));
}; -- |
@taozywu ok,i'll try it. |
6 clients send data once per minute. About twenty and twenty minutes after the server is being given.
The text was updated successfully, but these errors were encountered: