php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76868 PDO SQLite support for SQLite's Shared Cache Mode
Submitted: 2018-09-12 08:20 UTC Modified: 2024-07-28 10:23 UTC
Votes:13
Avg. Score:4.5 ± 0.7
Reproduced:11 of 11 (100.0%)
Same Version:3 (27.3%)
Same OS:2 (18.2%)
From: pablo dot godinez at zayon dot eu Assigned:
Status: Open Package: PDO SQLite
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pablo dot godinez at zayon dot eu
New email:
PHP Version: OS:

 

 [2018-09-12 08:20 UTC] pablo dot godinez at zayon dot eu
Description:
------------
From SQLite's documentation : (https://www.sqlite.org/sharedcache.html)

> Beginning with SQLite version 3.7.13 (2012-06-11), shared cache can be used on in-memory databases, provided that the database is created using a URI filename

> Enabling shared-cache for an in-memory database allows two or more database connections in the same process to have access to the same in-memory database

It is possible in php to create such connection to an SQLite database using sqlite3_open function but not using PDO. 

PDO should support this URI : `sqlite::memory:?cache=shared`.

This feature would be useful for tests performances purposes. To use the memory mode we currently have to manually have each process attach to the original opened connection in order to have access to the same database.

Relevant links :

https://stackoverflow.com/questions/16487679/shared-cache-on-pdo-sqlite
https://stackoverflow.com/questions/9150319/enable-shared-pager-cache-in-sqlite-using-php-pdo
https://github.com/doctrine/dbal/issues/2901


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-28 15:39 UTC] mikeryan at virtuoso-performance dot com
I would like to add that the lack of the shared cache isn't just a performance issue - when testing library code which is making its own PDO connection, you can't have the test code prepopulate an in-memory database table with test data.
 [2019-08-25 01:53 UTC] jsuprock at tenable dot com
This is actually preventing me from setting up mock, in-memory databases to inject for fully unit-testing much of our project's code.

Do you know when this will be available? I would greatly appreciate it.

Thanks!
 [2021-10-07 11:37 UTC] cmb@php.net
Something like what has been done for SQLite3[1], would need to be
done for PDO_SQLite.  Maybe someone wants to submit a PR[2]?

[1] <https://github.com/php/php-src/commit/cc125f277b50e0f90fc8033fe7f47d2446389a15>
[2] <https://github.com/php/php-src/pulls>
 [2021-11-18 12:54 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-11-18 12:54 UTC] cmb@php.net
> PDO should support this URI : `sqlite::memory:?cache=shared`.

As of PHP 8.1.0, the following is supported having the same effect:

    sqlite:file::memory:?cache=shared

However, that doesn't work, if open_basedir is set.  Would that be
a problem for you?
 [2021-11-28 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2022-06-27 03:56 UTC] mortensonsam at gmail dot com
>However, that doesn't work, if open_basedir is set.  Would that be a problem for you?

Chiming in to say that yes, this is a problem for me! I'd like to use this feature and keep my open_basedir restriction in place for security reasons.
 [2022-06-27 10:31 UTC] cmb@php.net
-Status: No Feedback +Status: Open
 [2024-07-28 10:23 UTC] cmb@php.net
-Status: Assigned +Status: Open -Assigned To: cmb +Assigned To:
 [2024-07-28 10:23 UTC] cmb@php.net
I haven't looked closely into this, but

> Enabling shared-cache for an in-memory database allows two or
> more database connections in the same process to have access to
> the same in-memory database

looks like an issue for threaded APIs, where open_basedir might
mitigate some of these issues.

And the OP states also:

> This feature would be useful for tests performances purposes.

For such testing purposes, open_basedir should not be relevant.

If anybody is still interested in a variant which is not
constrained by open_basedir, I suggest to file a ticket at
<https://github.com/php/php-src/issues> for better visibility.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC