swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.42k stars 3.16k forks source link

MySQL server has gone away due to Connection timed out - prepare result #5495

Open DevilSerj opened 1 week ago

DevilSerj commented 1 week ago

Please answer these questions before submitting your issue.

  1. What did you do? If possible, provide a simple script for reproducing the error.

    go(function () {
        $config = Config::get('database.connections.mysql');
        $db = new MySQL();
        $server = array(
            'host' => $config['host'],
            'port' => $config['port'],
            'user' => $config['username'],
            'password' => $config['password'],
            'database' => $config['database'],
        );
    
        echo "connect\n";
        $ret1 = $db->connect($server);
        var_dump($ret1);
    
        echo "prepare [1]\n";
        $stmt1 = $db->prepare('SELECT * FROM users WHERE id=?', 5);
        var_dump($stmt1);
        if ($stmt1 == false)
        {
            var_dump($db->errno, $db->error);
        }
    });
  2. What did you expect to see? A positive result prepare

  3. What did you see instead? connect bool(true) prepare [1] bool(false) int(2006) string(77) "SQLSTATE[HY000] [2006] MySQL server has gone away due to Connection timed out"

  4. What version of Swoole are you using (show your php --ri swoole)? PHP | 7.4.33 | Swoole | 4.8.13 |

  5. What is your machine environment used (show your uname -a & php -v & gcc -v) ? Linux

jingjingxyk commented 1 week ago

Code Try to reconnect to the database.

https://github.com/swoole/swoole-src/issues/4131#issuecomment-815353916

more info : https://github.com/jingjingxyk/swoole-cli/issues/125

DevilSerj commented 1 week ago

Code Try to reconnect to the database.

#4131 (comment)

more info : jingjingxyk/swoole-cli#125

Of course I understand this and I have tried many different options and reconnect as well. But it doesn't work for me, the connection is bigger, I easily use the query method and it works. I have a task that creates coroutines and I need to have a separate connection within the coroutine and I was thinking of doing it using Swoole/Coroutine/Mysql as I expected it to work better. But it doesn't work for me and I used a normal pdo and just create a meal through it.

Maybe I should update swoole and php but now I can't do it yet.