note 118909 added to ref.pdo-sqlite.connection
| From: | (.) | Date: | Thu, 25 Feb 2016 22:32:11 +0000 |
| Subject: | note 118909 added to ref.pdo-sqlite.connection | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205046@lists.php.net to get a copy of this message | ||
Some notes that may or may not be obvious..
In general, when using an in-memory (:memory:) database from within a PHP script (such as code in an
index.php file for a web server), the memory used for the database exists only as long as the PHP
code is running. Usually, this is only as long as it takes to deliver output back to the web server
trying to serve the web page to the client. There is no way (that I know of, please correct me if
I'm wrong) to share an in-memory database across different web connections, including different
multiple connections from the same client. *This does include "persistent" connections.*
The reason for this is because in-memory databases *are* in-memory databases, and the memory
allocated by the web server/PHP processor is allocated and released "on the fly".
Otherwise, web servers which serve thousands of web pages would quickly consume all available memory
(and swap space), and come to a grinding halt when the system no longer has available memory to
handle more requests.
If you need to share data across sessions, connections, or scripts, you'll need to use a
database file in a folder/directory which is *writable* by the web server/PHP extension, as SQLite3
may use some temporary files while working with the database. (In my Debian Linux installation, this
is the "www-data" psuedo-user/group.) (You can consult the SQLite3 documentation if you
wish to know what temporary files it uses; They are well-documented.)
In short, it is a _logical_error_ to think of in-memory databases as anything other than very
short-term temporary databases. They may be useful if you only wish to work with a subset of a
larger database within *a single web page, AND only while the PHP script is generating the web
page*. That is, you cannot use in-memory databases to store a user's "shopping cart",
for example, because a shopping cart would still need to load many different web pages, invoking
many different PHP scripts, each with their own memory space. Likewise, once PHP has generated the
output of the web page for the server to send on to the client, PHP is no longer "part of the
picture", and any memory it had allocated may be freed for other uses--including your in-memory
database.
This is not a limitation of the web server, PHP, or SQLite, but of how operating systems work in
general to share limited resources (such as memory) between processes/users/connections/et cetera.
----
Server IP: 72.52.91.14
Probable Submitter: 67.187.255.205
----
Manual Page -- http://php.net/manual/en/ref.pdo-sqlite.connection.php
Edit -- https://master.php.net/note/edit/118909
Del: integrated -- https://master.php.net/note/delete/118909/integrated
Del: useless -- https://master.php.net/note/delete/118909/useless
Del: bad code -- https://master.php.net/note/delete/118909/bad+code
Del: spam -- https://master.php.net/note/delete/118909/spam
Del: non-english -- https://master.php.net/note/delete/118909/non-english
Del: in docs -- https://master.php.net/note/delete/118909/in+docs
Del: other reasons-- https://master.php.net/note/delete/118909
Reject -- https://master.php.net/note/reject/118909
Search -- https://master.php.net/manage/user-notes.php