Skip to content

Commit 5e8f817

Browse files
author
Carl Sverre
committed
Added ATTR_PERSISTENT documentation
ci skip
1 parent 4adeeea commit 5e8f817

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This package is currently in a pre-release beta, please use with caution and ope
99
- [Install](#install)
1010
- [Usage](#usage)
1111
- [Issues connecting to SingleStore Managed Service](#issues-connecting-to-singlestore-managed-service)
12+
- [Persistent Connections (performance optimization)](#persistent-connections-performance-optimization)
1213
- [PHP Versions before 8.1](#php-versions-before-81)
1314
- [Migrations](#migrations)
1415
- [Universal Storage Tables (Columnstore)](#universal-storage-tables-columnstore)
@@ -97,6 +98,24 @@ If you are encountering issues connecting to the SingleStore Managed Service, it
9798
]) : [],
9899
```
99100

101+
## Persistent Connections (performance optimization)
102+
103+
In general, we recommend enabling `PDO::ATTR_PERSISTENT` when connecting to SingleStoreDB. This is because opening new connections to SingleStoreDB is very expensive compared to running many transactional queries. By using `PDO::ATTR_PERSISTENT`, you can greatly improve the performance of transactional workloads.
104+
105+
The only downside to using persistent connections is that you need to ensure that transactions are correctly cleaned up as well as being careful when changing session variables or the context database. [You can read more about this feature in the official documentation on php.net][attr_persistent].
106+
107+
Also, note that SingleStoreDB in it's default configuration can handle very large numbers of idle connections with no performance impact. The default is roughly 100,000 idle connections per aggregator, but that can be set much higher if your server can handle it.
108+
109+
To enable this feature, simply update your options to include `PDO::ATTR_PERSISTENT => true`:
110+
111+
```php
112+
'options' => extension_loaded('pdo_mysql') ? array_filter([
113+
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
114+
PDO::ATTR_EMULATE_PREPARES => true,
115+
PDO::ATTR_PERSISTENT => true,
116+
]) : [],
117+
```
118+
100119
## PHP Versions before 8.1
101120

102121
In PHP versions before 8.1, the flag `PDO::ATTR_EMULATE_PREPARES` results in a bug by which all attributes returned by MySQL (and
@@ -403,4 +422,5 @@ IF YOU OR YOUR COMPANY DO NOT AGREE TO THESE TERMS AND CONDITIONS, DO NOT CHECK
403422
[persisted computed column]: https://docs.singlestore.com/managed-service/en/create-a-database/physical-database-schema-design/procedures-for-physical-database-schema-design/using-persistent-computed-columns.html
404423
[singlestore-pem]: https://portal.singlestore.com/static/ca/singlestore_bundle.pem
405424
[Eloquent's attribute casting]: https://laravel.com/docs/9.x/eloquent-mutators#attribute-casting
406-
[create table]: https://docs.singlestore.com/managed-service/en/reference/sql-reference/data-definition-language-ddl/create-table.html
425+
[create table]: https://docs.singlestore.com/managed-service/en/reference/sql-reference/data-definition-language-ddl/create-table.html
426+
[attr_persistent]: https://www.php.net/manual/en/features.persistent-connections.php

0 commit comments

Comments
 (0)