Return HTTP 200 response before continuing processing

  //--------------------------------------------
  //----- RETURN HTTP RESPONSE IMMEDIATELY -----
  //--------------------------------------------
  $OutputHtml = null;

  //Check if fastcgi_finish_request is callable
  if (is_callable('fastcgi_finish_request'))
  {
    if ($OutputHtml !== null)
      echo $OutputHtml;

    session_write_close();      //Close the session
    ignore_user_abort(True);    //Prevent echo, print, and flush from killing the script
    fastcgi_finish_request();   //This returns 200 to the user, and processing continue
  }
  else
  {
    ignore_user_abort(true);    //Prevent echo, print, and flush from killing the script
    ob_start();

    if ($OutputHtml !== null)
      echo $OutputHtml;
    
    header('Connection: close');
    header('Content-Length: '.ob_get_length());
    ob_end_flush();
    ob_flush();
    flush();
  }
  //CARRY ON HANDLING SCRIPT AS SLOWLY AS YOU WANT WITH RESPONSE ALRERADY SENT
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.