views:

57

answers:

3
  1. In PHP is it possible (and is it safe) to close the http connection without returning any http status code? My server is apache.
  2. Will this be logged to the access log or error log?
+3  A: 

I don't think this is possible: Ultimately it's Apache who closes the connection, and returns a status code if PHP doesn't emit one.

We had a question some time ago about whether http connections can be forcibly cut off from within PHP. IIRC, the consensus was that except for shooting down the web server thread responsible for the current request, this was not possible. Looking for the question now... Update: Can't find it right now, sorry.

Pekka
Thanks for your answer. Actually I need to ban some *bad* http requests without even logging them to access_log
mmonem
@mmondm That's Apache module material.
Artefacto
Because I have so frequent requests that result in the MySQL 'too many connections'; the problem we discussed 7 hours ago @Pekka
mmonem
I agree with @Artefacto, a bad request (bad as in evil, DoS, things like that, correct?) is something that should be determined and blocked long before PHP kicks in
Pekka
@mmonem ah, I see! Makes sense. Are you being DoS'ed from outside? In that case, head over to serverfault.com, there should be material on that there.
Pekka
yes it is DoS request
mmonem
@mmonem see e.g. http://serverfault.com/questions/148515/how-are-suspected-dos-attacks-handled-by-webservers or http://serverfault.com/questions/43752/apache-gets-clogged-with-certain-requests ... lots more over there http://serverfault.com/search?q=Apache+Dos
Pekka
Merci, Pekka! Appreciate this!
mmonem
+1  A: 

I don't think so, short of killing the apache worker itself, which would certainly not be a good idea.

It may be possible if using PHP as an Apache module. There may be some Apache internal function available to modules that you could use for this, but I don't know enough of Apache internals to tell for sure.

Artefacto
+1  A: 

In nutshell Apache calling the shots, and you cannot change Apache behaviour from outside, for security reasons.

aromawebdesign.com