title: Detect when running time is near max_execution_time
body: <p>I want my script to detect when it's near the maximum execution time, so it can stop and update the database.</p>
  
  <p>I know phpMyAdmin does something like this when importing large files, I just don't know how.</p>
  
  <p><code>register_shutdown_function()</code> won't work as far as I can tell. It will work when doing a simple <code>echo "test";</code>, but not when doing any database operation. Any ideas?</p>