laravel-oci8
laravel-oci8 copied to clipboard
Allow connection timeout to be passed as parameter when creating oci_connect
Connection timeout
When we are creating db connection we need to use connection timeout as described here: https://www.php.net/manual/en/function.oci-connect.php#refsect1-function.oci-connect-parameters, oci_connect's connection_string is capable of handling timeout parameter if passed like this./db?connect_timeout=10
Code snippet of problem
For example allow additional options to be sent when creating oci_connect, we can only send dns but we need additional parameter:
public function __construct($dsn, $username, $password, array $options = [])
{
$dsn = (string) trim($dsn);
if (strpos($dsn, 'oci:') === 0) {
$connectStr = preg_replace('/^oci:/', '', $dsn);
parse_str(str_replace(';', '&', $connectStr), $connectParams);
if (empty($connectParams['dbname'])) {
throw new Oci8Exception('Invalid connection string');
} else {
$dsnStr = str_replace('//', '', $connectParams['dbname']);
if (isset($connectParams['host']) && isset($connectParams['port'])) {
$host = $connectParams['host'] . ':' . $connectParams['port'];
} elseif (isset($connectParams['host'])) {
$host = $connectParams['host'];
}
if (! empty($host)) {
$dsnStr = $host . '/' . $dsnStr;
}
// A charset specified in the connection string takes
// precedence over one specified in $options
! empty($connectParams['charset'])
? $charset = $this->configureCharset($connectParams)
: $charset = $this->configureCharset($options);
$dsn = $dsnStr;
}
} else {
$charset = $this->configureCharset($options);
}
$this->connect($dsn, $username, $password, $options, $charset);
// Save the options
$this->options = $options;
}
System details
- Operating System: centos
- PHP Version: 7.2.7
- Laravel Version: 5.8
- Laravel-OCI8 Version: 5.8.2
Further options were introduced with Oracle 19c, including timeout and keep-alive settings.
Unfortunately, we still uses lower version of Oracle and might not be able to support this atm. Please do not hesitate to submit a PR if you can. Will try to implement when I got the chance. Thanks!