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()) {
                //Logic
            } else {
                //Logic
            }
        } 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?

Thanks

UPD:

Need add flag param to datasource

'flags' => [
    PDO::ATTR_TIMEOUT => 1
    //1 second timeout
],

More information: https://www.php.net/manual/ru/pdo.constants.php