How to stop PHP code execution?
php
Solution
Please see the following information from user Pekka 웃
According to the manual, destructors are executed even if the script gets terminated using `die()` or `exit()`:
The destructor will be called even if script execution is stopped using `exit()`. Calling exit() in a destructor will prevent the remaining shutdown routines from executing.
According to this PHP: destructor vs register_shutdown_function, the destructor does not get executed when PHP's execution time limit is reached (Confirmed on Apache 2, PHP 5.2 on Windows 7).
The destructor also does not get executed when the script terminates because the memory limit was reached. (Just tested)
The destructor does get executed on fatal errors (Just tested) Update: The OP can't confirm this - there seem to be fatal errors where things are different
It does not get executed on parse errors (because the whole script won't be interpreted)
The destructor will certainly not be executed if the server process crashes or some other exception out of PHP's control occurs.
Referenced in this question Are there any instances when the destructor in PHP is NOT called?
Problem
Is there a way to immediately stop PHP code execution? I am aware of exit but it clearly states: Terminates execution of the script. Shutdown functions and object destructors will always be executed even if exit is called. So what I want to achieve is to stop the PHP code execution exactly when I call exit or whatever. Any help? Edit: After Jenson's answer Trial 1: ``` function newExit() { __halt_compiler(); } echo "start"; newExit(); echo "you should not see this"; ``` Shows `Fatal error: __HALT_COMPILER() can only be used from the outermost scope in` which was pretty expected. Trial 2: ``` function newExit() { include 'e.php'; } echo "start"; newExit(); echo "you should not see this"; ``` e.php just contains `__halt_compiler();` This shows startyou should not see this Edit: Why I want to do this? I am working on an application that includes a proprietary library (required through virtual host config file to which I don't have access) that comes as encrypted code. Is a sort of monitoring library for security purpose. One of it's behaviours is that it registers some shutdown functions that log the instance status (it saves stats to a database) What I want to do is to disable this logging for some specific conditions based on (remote IP)