class UnregisterableCallback{
// Store the Callback for Later
private $callback;
// Check if the argument is callable, if so store it
public function __construct($callback)
{
if(is_callable($callback))
{
$this->callback = $callback;
}
else
{
throw new InvalidArgumentException(“Not a Callback”);
}
}
// Check if the argument has been unregistered, if not call it
public function call()
{
if($this->callback == false)
return false;
$callback = $this->callback;
$callback(); // weird PHP bug
}
// Unregister the callback
public function unregister()
{
$this->callback = false;
}
}
Basic usage:
$callback = new UnregisterableCallback(array($object, “myFunc”));
register_shutdown_function(array($callback, “call”));
To unregister
$callback->unregister();
转自:https://stackoverflow.com/questions/2726524/can-you-unregister-a-shutdown-function
转载请注明:Findever » php解决shutdown回调死循环问题【转】