sqlite errors in multithread PHP script <p>I need to update single sqlite database from different separated PHP threads, all running at the same time. Below is the code for db connection</p> <pre><code> $db = new SQLite3(__DIR__.'/proxy.db'); $db-&gt;busyTimeout(5000000); $db-&gt;exec('PRAGMA journal_mode=WAL;'); $db-&gt;exec('PRAGMA temp_store=2;'); $db-&gt;exec('PRAGMA synchronous=0;'); </code></pre> <p>And this is the different methods for updating...</p> <pre><code> $db-&gt;query('BEGIN TRANSACTION;UPDATE proxy SET lastused='.time().' WHERE id='.$row['id'].';COMMIT;'); $db-&gt;query('BEGIN DEFERRED;UPDATE proxy SET lastused='.time().' WHERE id='.$row['id'].';COMMIT;'); $db-&gt;query('BEGIN IMMEDIATE;UPDATE proxy SET lastused='.time().' WHERE id='.$row['id'].';COMMIT;') </code></pre> <p>all of them <em>sometime</em> return error: "Unable to execute statement: SQL logic error or missing database". If remove begin-commit code, then I got SQLite3::query(): database is locked.</p> <p>Can I somehow change the code to get rid of those errors (but still use <em>separated</em> multi-threaded processes)?</p>