Search code examples
phphttpresponseexitbandwidth

absolutely no response php exit technique?


The docs I read don't seem clear on this issue.

When calling exit() with no arguments, does the server still send something back to the client?

If so, is there an alternative or way to keep anything from being sent to the client on exit?


Solution

  • exit is basically the same as reaching the end of the file. Anything that has already been sent will be received by the browsers, and any output buffers will be processed and also sent.

    You can force an empty response by include ob_start() as your first line of code, and using this function:

    function exitEmpty() {
        while(ob_get_level()) ob_end_clean();
        exit;
    }
    

    However the headers will still be sent. This just empties the response body.