Skip to content
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

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

Open
DevilSerj opened this issue Sep 26, 2024 · 3 comments
Open

Comments

@DevilSerj
Copy link

DevilSerj commented Sep 26, 2024

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);
        }
    });
  1. What did you expect to see?
    A positive result prepare

  2. 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"

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

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

@jingjingxyk
Copy link
Contributor

Code Try to reconnect to the database.

#4131 (comment)

more info : jingjingxyk/swoole-cli#125

@DevilSerj
Copy link
Author

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.

@Draghmar
Copy link

Are you using connection pool outside of that example you gave above? Maybe you've hit your server limit and that's why you can't create additional connections?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants