Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow connection timeout to be passed as parameter when creating oci_connect #636

Open
ognjenVlad opened this issue Feb 23, 2021 · 1 comment

Comments

@ognjenVlad
Copy link

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
@yajra
Copy link
Owner

yajra commented Jan 31, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants