最新消息:欢迎光临!

php解决shutdown回调死循环问题【转】

php findever 178浏览 0评论

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回调死循环问题【转】

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址