title: How to implement background/asynchronous write-behind caching in PHP?
body: <p>I have a particular PHP page that, for various reasons, needs to save ~200 fields to a database.  These are 200 separate insert and/or update statements.  Now the obvious thing to do is reduce this number but, like I said, for reasons I won't bother going into I can't do this.</p>
  
  <p>I wasn't expecting this problem.  Selects seem reasonably performant in MySQL but inserts/updates aren't (it takes about 15-20 seconds to do this update, which is naturally unacceptable).  I've written Java/Oracle systems that can happily do thousands of inserts/updates in the same time (in both cases running local databases; MySQL 5 vs OracleXE).</p>
  
  <p>Now in something like Java or .Net I could quite easily do one of the following:</p>
  
  <ol>
  <li>Write the data to an in-memory
  write-behind cache (ie it would
  know how to persist to the database
  and could do so asynchronously);</li>
  <li>Write the data to an in-memory cache
  and use the PaaS (Persistence as a
  Service) model ie a listener to the
  cache would persist the fields; or</li>
  <li>Simply start a background process
  that could persist the data.</li>
  </ol>
  
  <p>The minimal solution is to have a cache that I can simply update, which will separately go and upate the database in its own time (ie it'll return immediately after update the in-memory cache).  This can either be a global cache or a session cache (although a global shared cache does appeal in other ways).</p>
  
  <p>Any other solutions to this kind of problem?</p>