I have created custom mysqli driver and loaded from database.php, when I am calling any API from postman its creating connection pooling and getting connection from connection pool, and when request is completed connection is released back to connection pool using hook function, but problem is its creating connection every time I am hitting the api instead only once, how can I resolve this issue, I have included the sample code
require_once(BASEPATH . 'database/drivers/mysqli/mysqli_driver.php');
class CI_DB_MY_DB_mysqli_driver extends CI_DB_mysqli_driver
{
public static $connection_pool = [];
private $max_connections = 10;
private static $instance = null;
private static $initialized = false;
public function __construct($params)
{
parent::__construct($params);
}
public function initialize()
{
if (self::$initialized == false) {
$this->initialize_connection_pool();
self::$initialized = true;
}
parent::initialize();
}
private function initialize_connection_pool()
{
if (count(self::$connection_pool) == 0) {
for ($i = 0; $i < $this->max_connections; $i++) {
self::$connection_pool[] = parent::db_connect();
}
}
}
public function db_connect($presistence = TRUE)
{
if (!empty(self::$connection_pool)) {
$connection = array_pop(self::$connection_pool);
return $connection;
}
return parent::db_connect();
}
public function release_connection($connection)
{
self::$connection_pool[] = $connection;
}
}