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 6911593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:58:38+00:00 2026-05-27T08:58:38+00:00

I have a gateway script that returns JSON back to the client. In the

  • 0

I have a gateway script that returns JSON back to the client.
In the script I use set_error_handler to catch errors and still have a formatted return.

It is subject to ‘Allowed memory size exhausted’ errors, but rather than increase the memory limit with something like ini_set(‘memory_limit’, ’19T’), I just want to return that the user should try something else because it used to much memory.

Are there any good ways to catch fatal errors?

  • 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-27T08:58:39+00:00Added an answer on May 27, 2026 at 8:58 am

    As this answer suggests, you can use register_shutdown_function() to register a callback that’ll check error_get_last().

    You’ll still have to manage the output generated from the offending code, whether by the @ (shut up) operator, or ini_set('display_errors', false)

    ini_set('display_errors', false);
    
    error_reporting(-1);
    
    set_error_handler(function($code, $string, $file, $line){
            throw new ErrorException($string, null, $code, $file, $line);
        });
    
    register_shutdown_function(function(){
            $error = error_get_last();
            if(null !== $error)
            {
                echo 'Caught at shutdown';
            }
        });
    
    try
    {
        while(true)
        {
            $data .= str_repeat('#', PHP_INT_MAX);
        }
    }
    catch(\Exception $exception)
    {
        echo 'Caught in try/catch';
    }
    

    When run, this outputs Caught at shutdown. Unfortunately, the ErrorException exception object isn’t thrown because the fatal error triggers script termination, subsequently caught only in the shutdown function.

    You can check the $error array in the shutdown function for details on the cause, and respond accordingly. One suggestion could be reissuing the request back against your web application (at a different address, or with different parameters of course) and return the captured response.

    I recommend keeping error_reporting() high (a value of -1) though, and using (as others have suggested) error handling for everything else with set_error_handler() and ErrorException.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that uses the shared gateway pattern to implement an inversion
i have various strings that look like that: $(gateway.jms.jndi.ic.url,0,tibjmsnaming, tcp)/topic/$(gateway.destination.prefix)$(gateway.StatusTopicName),$(gateway.jms.jndi.ic.username),$(gateway.jms.jndi.ic.password),abinding,tBinding i'm trying to figure
I have powershell script which sends text message through a sms-gateway. I get the
I have a kind of Http-Gateway app, which acts as an http client towards
Suppose I have a website that receives money through a payment gateway when people
Suppose I have: <a href=http://www.yahoo.com/ target=_yahoo title=Yahoo!&#8482; onclick=return gateway(this);>Yahoo!</a> <script type=text/javascript> function gateway(lnk) {
I have a gateway application that comes up with a login dialog and then
I have been trying to create a post login script that will change the
So at work i use a vpn connection and after that i have to
I have a script that sends SMS alerts using email to SMS gateways like

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.