Setting mysql connection timeout[Solved]

Hello. There was a problem setting the timeout for connecting to the mysql database. The case is this, I need to check the connection to one of the data sources and if the server is offline, do not wait for a timeout but immediately return the result. How can i do this?

Current implementation:

        $db = ConnectionManager::get('datasource');

        try {
            if ($db->connect()) {
            } else {
        } catch (\Exception $e) {
            //Return error

In this case, you have to wait a timeout of 30 seconds to get the result. How can the timeout be reduced?



Need add flag param to datasource

'flags' => [
    //1 second timeout

More information: