John Davidson

php - PDO_OCI (Oracle) with persistent connections - any way to set max_persistent, persistent_timeout etc.?

0 comments
Message:


I am using PHP 7.4 with PDO_OCI extension to connect to Oracle 19c (with Oracle Instant Client on Windows).


It all works fine, however I've noticed that connecting to the database is a bit slow and if I switch to using persistent connections (PDO::ATTR_PERSISTENT => TRUE), PHP pages open significantly faster.


My question is: is this in any way configurable?


When using standard Oracle OCI8 module, there are such settings in PHP.ini as oci8.max_persistent, oci8.persistent_timeout or oci8.ping_interval that modify the behaviour of persistent connections... is there any equivalent for PDO_OCI? I'm just a bit worried that some bug can cause thousands of zombie connections being created...



My Answer:
true), the performance improves significantly. However, I am concerned about potential issues with persistent connections, such as running out of resources or connections not being properly closed.

In PHP's PDO extension, there is no direct way to set options such as max_persistent or persistent_timeout for Oracle connections. These options are typically available in other database extensions, such as PDO_MySQL.

However, you can still control the behavior of persistent connections in PDO_OCI by setting the appropriate environment variables in your PHP configuration or in your script before establishing a connection. Here are a few options you can consider:

1. Set the `OCI8` environment variables: You can set environment variables such as `OCI8_MAX_PERSISTENT`, `OCI8_PERSISTENT_TIMEOUT`, and `OCI8_PERSISTENT_CHECK_INTERVAL` to control the behavior of persistent connections in PDO_OCI. These variables can be set in your php.ini file or in your script using `putenv()` function.

2. Use connection pooling: Oracle provides connection pooling as a way to manage and reuse database connections efficiently. You can configure connection pooling settings in your Oracle database and use PDO_OCI to connect to the pooled connections. This can help improve performance and manage resources effectively.

3. Implement your own connection management: If you have specific requirements for managing persistent connections, you can implement your own connection management logic in your PHP script. For example, you can create a connection pool in your script and reuse connections based on your own criteria.

Overall, while PDO_OCI may not provide direct options for setting max_persistent or persistent_timeout, you can still control the behavior of persistent connections by using environment variables, connection pooling, or custom connection management logic. It's important to test and monitor the performance and resource usage of your application to ensure that persistent connections are being used effectively.

Rate this post

3 of 5 based on 7226 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us