Welcome Guest, Not a member yet? Register   Sign In
Mysql gone Away error pls HELP!
#1
Sad 
(This post was last modified: 03-13-2022, 10:36 AM by user601.)

Hi all. Pls help me with CI4 latest. I using workerman websockets with CI4. But later 4 hours server give next error: "ERROR - 2022-03-13 03:21:09 --> MySQL server has gone away" ON EVERITHYNC REQUEST AND CONNECT ((( . 
Code example:
PHP Code:
<?php
//BASE CLASS FOR ALL MODELS
//namespace App\Models;

//use Exception;

//class CodeIgniterDataBaseModel
//{
//    public $dataBase = null;
//
//    public function __construct(string $nameDataBase)
//    {
//        $this->SetDataBase($nameDataBase);    
//    }
//
//    public function SetDataBase(string $nameDataBase)
//    {
//        $this->dataBase = db_connect($nameDataBase);
//    }

//    public function Query(string $sql, array $array = [])
//    {
//        $result = [];
//        try
//        {
//            $query = $this->dataBase->query($sql, $array);
//        }
//        catch(Exception $e)
//        {
//            $this->Reconnect();
//            $query = $this->dataBase->query($sql, $array);
//        }
//        $this->PrepareQueryResult($query,$result);
//        return $result;
//    }

//    public function IsConnected()
//    {
//        return !empty( $this->dataBase->Query("SELECT VERSION();") );
//    }

//    public function Reconnect()
//    {
//        $this->dataBase->reconnect();
//    }

//    public function Close()
//    {
//        $this->dataBase->close();
//    }  
//};

namespace App\Services\BoostServer;
require_once 
__DIR__.'/../framework.php';
require_once 
__DIR__.'/../../Libraries/workerman/Worker.php';

use 
App\Models\SessionModel;
use 
App\Models\RoomModel;
use 
Workerman\Worker;
use 
Exception;

$webSocket = new Worker"websocket://localhost:9090");

$webSocket->onWorkerStart = function($task)
{
    SessionModel::SetDataBase('default');
    RoomModel::SetDataBase('default');
};

$webSocket->onConnect = function ($connection) use(&$room)
{
    $connection->onWebSocketConnect = function($connection)
    {
       //NOT HELPING WITH PROBLEM - MySQL GONE AWAY and all request giving null result
        try
        {
            if(
                SessionModel::$dataBase->IsConnected() == false ||
                RoomModel::$dataBase->IsConnected() == false
            
)
            {
                SessionModel::SetDataBaseNS('default');
                RoomModel::SetDataBaseNS('default');
            }
        }
        catch(Exception $error)
        {
            SessionModel::SetDataBaseNS('default');
            RoomModel::SetDataBaseNS('default');
        }
 
  
   
// Mysql Request
        //...
    };
};

$webSocket->onMessage = function ($connection$message) use(&$room, &$config){};

$webSocket->onClose = function ($connection){}

Worker::runAll();
$server->run();
?>

It's very long running script. I run this on next command "php app/Services/BoostServer/BoostServer.php start". How i can fix this problem? PLS HELP FIX HERE! 
P.S sorry my english not good
Reply




Theme © iAndrew 2016 - Forum software by © MyBB