Return HTTP 200 response before continuing processing

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

  //$OutputHtml = //<<<Set content if you want to return content<<<<<<

  //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
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *