4

I am not completely sure that this is possible from within PHP or even the HTTP protocol in depth. Is it possible to receive PHP script to run when it is requested but then the script drops the connection? Without replying?

Hopefully my question makes sense.

(I am using Apache)

  • I might try the sleep thing. Is there any more official way that will not require any resources? –  Jan 16 '09 at 10:19

5 Answers5

6

When you serve php through Apache, there will always be a http response. Calling exit will just stop php from processing - not stop Apache. The proper thing to do in your case, is probably to send a http response-code other than 200 (OK). For example 404 or 500. Check the specs to find the one that applies to your situation.

You send a http response from within php, using:

<?php
  header("HTTP/1.0 404 Not Found");
  exit;
troelskn
  • 115,121
  • 27
  • 131
  • 155
3

You can use exit() or die() in the script to stop script execution, would that do what you want?

Mat
  • 202,337
  • 40
  • 393
  • 406
  • Will that cause a HTTP reply? –  Jan 16 '09 at 11:44
  • 1
    I would like it to simply not reply, to time out by forgetting about the connection. Sleeping doesn't really do this because it is still 'around' but for later. –  Jan 16 '09 at 17:17
3

If you don't want to send any data at all, use a sleep in a loop. Eventually the client end will time out and close the connection.

1

Why would you want to do this? Surely you should be sending some kind of HTTP error code instead?

Tim Wardle
  • 1,723
  • 1
  • 14
  • 14
1

That depends on the software you use. Apache for example terminates any scripts as soon as the connection closes.

Georg Schölly
  • 124,188
  • 49
  • 220
  • 267