David Pratt
David Pratt

Reputation: 723

Writing a SQLite db loaded using :memory to disk

I'm generating quite a substantial (~50Mb) SQLite3 database in memory that I need to be able to write to disk once the generation of said database is complete. What is the best way of approaching this using PHP?

I have tried creating a structurally identical SQLite3 db on disk, and then using INSERTS to populate it, but it is far too slow. I have also drawn a blank looking at the online PHP SQLite3 docs.

What I have found is the SQLite3 Backup API, but not sure how best to approach interfacing with it from PHP. Any ideas?

Upvotes: 4

Views: 1212

Answers (1)

CL.
CL.

Reputation: 180192

The backup API is not available in PHP.

If you wrap all INSERTs into a single transaction, the speed should be OK.

You could avoid the separate temporay database and make the disk database almost as fast by increasing the page cache size to be larger than 50 MB, disabling journaling, and disabling synchronous writes.

Upvotes: 5

Related Questions