You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
php hangs when auth_socket is set for the user #19222
Results in php hanging until MySQL timeouts instead of connecting to MySQL
Changing the auth plugin to caching_sha2_password solves the situation. I did not test what happens when I don't set the password or explicitly use the socket.
PHP Version
PHP 8.4.1 (cli) (built: Nov 25 2024 18:04:19) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.1, Copyright (c) Zend Technologies
with Zend OPcache v8.4.1, Copyright (c), by Zend Technologies
I created a user authenticated via auth_socket.
Then I tried connecting with the unix domain socket (/var/run/mysqld/mysqld.sock), and it works fine.
Then I tried connecting via localhost without the mysqlnd socket specified in the constructor, and it correctly throws a mysqli_sql_exception.
So I can't reproduce the behaviour.
Something is probably off in your setup.
Also please note that PHP 8.4.1 is very outdated. Please retry on a more recent version.
Not specifying the socket also worked for me fine: I get an error instead of a timeout.
Please check the mysqli.default-socket php.ini setting.
Also please check if explicitly specifying the socket works, and double check your environment settings.
If nothing stands out, you can try running php under strace (i.e. strace php script.php) to see all the system calls being executed and see where it hangs.
Here is the relevant part from strace. Looks for me like php is trying to authenticate with caching_sha2_password while already logged in through socket.
Did you name your account the same as your local username? With a different user I get an error as well.
I can reproduce this as well. It only happens when using a non-empty string as password in the mysqli Constructor. It works fine when using an empty string as password in mysqli Constructor.
Since I don't like to install MySQL on my workstation, I use an LXC Container for reproduction. My steps:
lxc launch ubuntu24 u24
Add the MySQL vendor repository
apt install mysql-client mysql-server (use empty password when prompted)
Reproduced on 8.5.11 and master against MySQL 8.4.11, with an account IDENTIFIED WITH auth_socket AS 'root' and PHP running as root:
// php -d mysqlnd.net_read_timeout=5newmysqli('localhost', 'gh19222', 'secret', '', 0, '/var/run/mysqld/mysqld.sock');
// after 5 s: Unexpected server response while doing caching_sha2 auth: 0
For that account the server sends the OK right after the handshake response, and with a password mysqlnd_caching_sha2_handle_server_response() reads it as the fast auth status. The default branch sets the error but still returns PASS, so the caller then waits for an OK that already came.
I'd accept that OK the way libmysqlclient does and have the caller skip the read, which needs a new parameter on handle_server_response, so it would go to master. For PHP-8.4 the default branch could return FAIL instead, so it errors out right away. @kamil-tekiela@jonashrem does that sound right?
Activity
ndossche commentedon Jul 23, 2025
I created a user authenticated via auth_socket.
Then I tried connecting with the unix domain socket (
/var/run/mysqld/mysqld.sock), and it works fine.Then I tried connecting via localhost without the mysqlnd socket specified in the constructor, and it correctly throws a
mysqli_sql_exception.So I can't reproduce the behaviour.
Something is probably off in your setup.
Also please note that PHP 8.4.1 is very outdated. Please retry on a more recent version.
jonashrem commentedon Jul 23, 2025
ah sorry regarding the php version. It is the same in 8.4.10. I downgraded it to test if this can be reproduced in older versions.
I didn't explictly specify the socket but a username and password.
As my my.cnf contained the socket
'localhost' is automatically rewritten to using the socket through here but I'd still expected getting an error not a timeout.
ndossche commentedon Jul 23, 2025
Not specifying the socket also worked for me fine: I get an error instead of a timeout.
Please check the
mysqli.default-socketphp.ini setting.Also please check if explicitly specifying the socket works, and double check your environment settings.
If nothing stands out, you can try running php under strace (i.e.
strace php script.php) to see all the system calls being executed and see where it hangs.jonashrem commentedon Jul 24, 2025
Here is the relevant part from strace. Looks for me like php is trying to authenticate with caching_sha2_password while already logged in through socket.
Did you name your account the same as your local username? With a different user I get an error as well.
mariusklocke commentedon Jul 25, 2025
I can reproduce this as well. It only happens when using a non-empty string as password in the
mysqliConstructor. It works fine when using an empty string as password inmysqliConstructor.Since I don't like to install MySQL on my workstation, I use an LXC Container for reproduction. My steps:
lxc launch ubuntu24 u24apt install mysql-client mysql-server(use empty password when prompted)add-apt-repository ppa:ondrej/phpapt install php8.4-cli php8.4-mysqlVersions:
ojuschugh1 commentedon Oct 21, 2026
Reproduced on 8.5.11 and master against MySQL 8.4.11, with an account
IDENTIFIED WITH auth_socket AS 'root'and PHP running as root:For that account the server sends the OK right after the handshake response, and with a password
mysqlnd_caching_sha2_handle_server_response()reads it as the fast auth status. The default branch sets the error but still returns PASS, so the caller then waits for an OK that already came.I'd accept that OK the way libmysqlclient does and have the caller skip the read, which needs a new parameter on
handle_server_response, so it would go to master. For PHP-8.4 the default branch could return FAIL instead, so it errors out right away. @kamil-tekiela @jonashrem does that sound right?