Search code examples
phpmysqltimeoutmysql-connectdatabase-connection

How to connect PHP to MySQL as an interactive connection is it will use interactive_timeout instead of wait_timeout?


So, MySQL has wait_timeout and interactive_timeout. By default, MySQL connections we make use wait_timeout. I want to use interactive_timeout for connection with users so the timeout won't disturb user interaction. How can I create an interactive connection?

My current code is this:

$db_conn = mysqli_connect(HOSTNAME, DBUSERNAME, DBPASSWORD,DATABASE); 

Solution

  • https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_interactive_timeout

    "The number of seconds the server waits for activity on an interactive connection before closing it. An interactive client is defined as a client that uses the CLIENT_INTERACTIVE option to mysql_real_connect(). See also wait_timeout."

    and, from PHP:

    https://www.php.net/manual/en/mysqli.real-connect.php