void php_request_shutdown(void *dummy)
{
/*...*/

   php_deactivate_ticks(TSRMLS_C);

   /* 1. Call all possible shutdown functions registered
    * with register_shutdown_function()
    */
   if (PG(modules_activated)) zend_try {
      php_call_shutdown_functions(TSRMLS_C);
   } zend_end_try();

   /* 2. Call all possible __destruct() functions */
   zend_try {
      zend_call_destructors(TSRMLS_C);
   } zend_end_try();
   
   /* 3. Flush all output buffers */
   zend_try {
      zend_bool send_buffer =
         SG(request_info).headers_only ? 0 : 1;
      if (CG(unclean_shutdown)
         && PG(last_error_type) == E_ERROR
         && OG(ob_nesting_level)
         && !OG(active_ob_buffer).chunk_size
         && PG(memory_limit)
            < zend_memory_usage(1 TSRMLS_CC)) {
         send_buffer = 0;
      }
      php_end_ob_buffers(send_buffer TSRMLS_CC);
   } zend_end_try();

   /* 4. Send the set HTTP headers (note: This must be done
    * AFTER php_end_ob_buffers() !!)
    */
   zend_try {
      sapi_send_headers(TSRMLS_C);
   } zend_end_try();
   
   /* 5. Call all extensions RSHUTDOWN functions */
   if (PG(modules_activated)) {
      zend_deactivate_modules(TSRMLS_C);
      php_free_shutdown_functions(TSRMLS_C);
   }
   
   /* 6. Destroy super-globals */
   zend_try {
      int i;
      for (i=0; i<NUM_TRACK_VARS; i++) {
          if (PG(http_globals)[i]) {
              zval_ptr_dtor(&PG(http_globals)[i]);
          }
      }
   } zend_end_try();
   
   /* 6.5 free last error information */
   if (PG(last_error_message)) {
      free(PG(last_error_message));
      PG(last_error_message) = NULL;
   }
   if (PG(last_error_file)) {
      free(PG(last_error_file));
      PG(last_error_file) = NULL;
   }
   
   /* 7. Shutdown scanner/executor/compiler and restore ini
    * entries
    */
   zend_deactivate(TSRMLS_C);
   
   /* 8. Call all extensions post-RSHUTDOWN functions */
   zend_try {
      zend_post_deactivate_modules(TSRMLS_C);
   } zend_end_try();
   
   /* 9. SAPI related shutdown (free stuff) */
   zend_try {
      sapi_deactivate(TSRMLS_C);
   } zend_end_try();
   
   /* 10. Destroy stream hashes */
   zend_try {
      php_shutdown_stream_hashes(TSRMLS_C);
   } zend_end_try();
   
   /* 11. Free Willy (here be crashes) */
   zend_try {
      shutdown_memory_manager(CG(unclean_shutdown)
         || !report_memleaks, 0 TSRMLS_CC);
   } zend_end_try();
   
   /* 12. Reset max_execution_time */
   zend_try {
      zend_unset_timeout(TSRMLS_C);
   } zend_end_try();
   /* ... */
}