|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70248 lighweight function to detect that shutdown has started
Submitted: 2015-08-12 14:20 UTC Modified: 2015-08-12 14:49 UTC
From: raat1979 at gmail dot com Assigned:
Status: Closed Package: PHP options/info functions
PHP Version: Irrelevant OS: Irellevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: raat1979 at gmail dot com
New email:
PHP Version: OS:


 [2015-08-12 14:20 UTC] raat1979 at gmail dot com
At the moment the only way (i know of) to determine if a function is called during shutdown by means of a register_shutdown function is to do a debug_backtrace which is a resource heavy function or to enable output buffering and check for PHP_OUTPUT_HANDLER_END which also uses resources for the output buffering

It would preferable to have a way to check if the script is in shutdown mode using a more lightweight function.

I took an implementation of a static constructor/destructor for a utility class as example but it would be usable for many other purposes considers the implementation of static constructors but also does not see the need for destructors. 
I agree that there is no need to create a standard implementation for a static destructor. However should you need it it would be really practical to detect that shutdown has started without allocating a lot of resources.

Test script:
abstract class utilityClass{
 private static $_constructed = false;
 //seal the constructor to prevent creation even from subclasses
 final private function  __construct(){} 

 final public static function constructStatic(){
  if(self::$_constructed!==false) return;
  self::$_constructed = null;
  /* do construction here */
  self::$_constructed = true;
 final public static function destructStatic(){ 
  if(self::$_constructed!==true) return;
  // I REALLY DON'T LIKE THE BELOW debug_backtrace call
  if(count(($bt=debug_backtrace()))>1 || isset($bt[0]['file']) || isset($bt[0]['line'])) return;
  $_constructed = null;
  /* do destruction here */

  $_constructed = false;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-12 14:49 UTC] raat1979 at gmail dot com
-Status: Open +Status: Closed
 [2015-08-12 14:49 UTC] raat1979 at gmail dot com
I forgot the line 
"register_shutdown_function(array('utilityClass', 'destructStatic'));"
after "self::$_constructed = null;"
in the test script constructStatic, will issue a new one later
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Sep 28 05:03:38 2021 UTC