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

  • Home
  • SEARCH
  • 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 6020813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:37:21+00:00 2026-05-23T03:37:21+00:00

Is there any function / global variable in PHP that returns the current state

  • 0

Is there any function / global variable in PHP that returns the current state of the script (something like runnning, terminating)?

Or is the only way to set this state by making use of register_shutdown_function()?

That function looks inflexible to me as an already registered shutdown functions can be overriden with it. And the shutdown function gets executed when a user aborts the connection, which is not what I’m looking for explicitly and I don’t want to introduce too many constraints.

Are there any alternatives to register_shutdown_function() available? Or if not, how to deal with the shortcomings of that function?

UPDATE

Just to clarify: I’m not looking for connection state (e.g. connection_aborted()) but for the run state of the PHP script (running, terminating). Functions to find out more about the connection state I already know of, but how about the current state of the script? Has the script already been terminated and are objects (going to be) destroyed because of that?

UPDATE2

To clarify even more, I’m still not looking for connection state but for something comparable regarding the run-state. It should work in CLI as well which does not have any connection state as there is no TCP connection related to executing the code – to better illustrate what I’m looking for.

  • 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-23T03:37:22+00:00Added an answer on May 23, 2026 at 3:37 am

    After reading a larger part of the PHP sourcecode I came to the conclusion that even if such state(s) exist on the level of experience, they do not really exist within the interpreter in form of a flag or variable.

    The code about throwing Exceptions for example decides on various variables if that is possible or not.

    The answer to the question is no therefore.

    The best workaround I could find so far is to have a global variable for this which is set in a registered shutdown function. But a flag from PHP seems to be not really available.

    <?php
    
    register_shutdown_function(function() {$GLOBALS['shutdown_flag']=1;});
    
    class Test {
        public function __destruct() {
            isset($GLOBALS['shutdown_flag']) 
                && var_dump($GLOBALS['shutdown_flag'])
                ;
        }
    }
    
    $test = new Test;
    
    #EOF; Script ends here.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any function like php's mb_convert_encoding which can convert an encoding to another?
Are there any open source or commercial web programming language that function much like
Is there any function that converts an escaped Url string to its unescaped form?
As title; is there any function that can achieve this?
I'd like to assign part of the DOM tree to global variable, so that
Is there any function in c# equivalent to C's stdio function ungetc() ?
Is there any library function for this purpose, so I don't do it by
Is there any way to achieve function overloading in C? I am looking at
Is there any difference between int on_exit(void (*function)(int , void *), void *arg); and
Is there any way to make a function (the ones I'm thinking of are

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.