0

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
  • The headers will still be sent. Why do you not want to send anything? – Explosion Pills Jan 14 '13 at 01:45
  • It will send an empty HTTP body, if you did not output anything else. The webserver will still send a HTTP 200 status code, unless you manage to `kill` that parent process. – mario Jan 14 '13 at 01:45
  • @ExplosionPills for my site, when using the slider for dynamic pagination, jQuery will send tons of requests to the server. I can abort the AJAX request both server and client, but I want all communication between client and server to also stop once aborted by one side or the other. my bandwidth spikes during these slides. i want to prevent that –  Jan 14 '13 at 01:50
  • 2
    I'd fix your script first. – ceejayoz Jan 14 '13 at 01:51
  • It sounds like you probably don't want jQuery to send tons of requests... – Explosion Pills Jan 14 '13 at 01:52
  • @ceejayoz What needs fixing? –  Jan 14 '13 at 01:52
  • @ExplosionPills I want the dynamic pagination to happen quickly. I need the requests. I don't need any communication after abortion. –  Jan 14 '13 at 01:53

2 Answers2

4

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.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • That's much better! Thank-you! I take it you believe there is no way to cancel the response headers? –  Jan 14 '13 at 01:54
  • Not really. The browser sends the request and needs some kind of response. – Niet the Dark Absol Jan 14 '13 at 01:54
  • Does it need it if i've aborted client-side as well? Won't javascript just roll over the missing response headers, or will some sort of memory leak build? –  Jan 14 '13 at 01:55
0

exit() will still send headers, if they haven't already been sent, but otherwise it will send nothing else.

Leigh
  • 28,765
  • 10
  • 55
  • 103
AlienHoboken
  • 2,750
  • 20
  • 23
  • Not exactly true. If you `echo`ed/`print`ed/etc anything before the `exit()` command it will still get sent to the browser along with headers. – Ben D Jan 14 '13 at 01:54
  • True, but I thought he was only talking about sending the `exit()` command itself. – AlienHoboken Jan 14 '13 at 02:35