如何停止在PHP中运行的脚本

i am running a script in Zend Framework 2, the issue is how to stop the script from proceeding if certain conditions are not met

below is my function, you will note that i attempted to redirect the script if the condition of willMemberAcceptMessage() was not met

if(!$this->willMemberAcceptMessage())
        {  
            $this->flashMessenger()->addMessage(static::ERROR_UNABLE_TO_PROCEED);
            $this->redirect()->toUrl($url);
        } 

the problem is that the script does not redirect straight away, it still keeps running.

what should i do?

Actually the correct approach is to return the result of the redirect helper call, as each of its methods return the response object:

if (!$this->willMemberAcceptMessage()) {  
    $this->flashMessenger()->addMessage(static::ERROR_UNABLE_TO_PROCEED);
    return $this->redirect()->toUrl($url);
} 

You should avoid exit; calls if possible, and in this case, if you exit no redirect will happen.

add exit after redirect line

if(!$this->willMemberAcceptMessage())
        {  
            $this->flashMessenger()->addMessage(static::ERROR_UNABLE_TO_PROCEED);
            $this->redirect()->toUrl($url);
            exit;

        }