Req #70248 [NEW]: lighweight function to detect that shutdown has started

From: Date: Wed, 12 Aug 2015 14:20:28 +0000
Subject: Req #70248 [NEW]: lighweight function to detect that shutdown has started
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195155@lists.php.net to get a copy of this message
From: raat1979 at gmail dot com Operating system: Irellevant PHP version: Irrelevant Package: PHP options/info functions Bug Type: Feature/Change Request Bug description:lighweight function to detect that shutdown has started Description: ------------ 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 https://wiki.php.net/rfc/static_class_constructor 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; } }utilityClass::constructStatic(); -- Edit bug report at https://bugs.php.net/bug.php?id=70248&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70248&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70248&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70248&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70248&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70248&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70248&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70248&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70248&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70248&r=support Expected behavior: https://bugs.php.net/fix.php?id=70248&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70248&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70248&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70248&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70248&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70248&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70248&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70248&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70248&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70248&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70248&r=mysqlcfg

« previous php.bugs (#195155) next »