Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7444613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:32:59+00:00 2026-05-29T11:32:59+00:00

Is it possible to exit the script, say on a fatal error and still

  • 0

Is it possible to exit the script, say on a fatal error and still output my buffer? I am using a template system that executes the header/content/footer. So I am trying to make it so it’ll stop code executing on the fatal_error() function but still output the buffer template (which sends out the error message to the user while still maintaining the website template.) I use ob_start("ob_gzhandler") and in my fatal_error() function I use ob_flush() and I end up with a white screen when fatal_error() is called. Here’s my function

function fatal_error($error_message, $log = true)
{
    setup_error($error_message);

    ob_flush();
    exit();
}

setup_error() tells the script to change the content body to the error message (so it doesn’t parse 1/2 the body when the error occurs). All the examples I’ve looked through says ob_flush() or ob_end_flush() can achieve this, though I’m not having any luck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:33:00+00:00Added an answer on May 29, 2026 at 11:33 am

    Use the set_error_handler() function. This way you can assign a user-defined function, in your case fatal_error(), to execute when PHP encounters an error. You can do whatever you like in your function, including flushing the buffer and exiting.

    EDIT:

    The following code should do what you want:

    set_error_handler('fatal_error', E_ERROR, E_USER_ERROR);
    
    function fatal_error($errno, $errstr, $errfile, $errline)
    {
        ob_flush();
        exit();
    }
    

    EDIT 2:

    You can trigger an E_ERROR and therefore test the fatal_error() function like so:

    trigger_error('This is a test error', E_ERROR);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Automatic exit from bash shell script on error How can I have
Everyone. I am using an image resizer script that resizes JPG images. It worked
is it possible to use something like an vim-close/exit-Event to execute some last commands
Possible Duplicate: How do you send email from a Java app using Gmail? How
I have a psql script that looks like this: -- first set of statements
I'm working on a simple Python script that can use subprocess and/or os to
I can't seem to figure this one out. I have a validator-type script that
I'm using Eclipse Java EE IDE for Web Developers and want something like that:
Is it possible to measure the download speed of the Client with a script
Is it possible to edit a DFM (Delphi's form script format) in such a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.