I know that I can abort a script in PHP by calling exit or die. However, I would like not only to stop execution of a script, but also not even send a response to certain requests (resulting in a client side timeout).
If anyone could tell me how to do this I would really appreciate it. Thanks!
EDIT: I am sorry that I cannot be more specific as to why I am doing this, but I cannot because of the nature of the project. What I will say is that I am dealing with a bot.
Client side timeout means when you make an ajax request but the server takes too long to respond. If you really really want to accomplish this, I guess the way would be to put a big sleep() statement, so that the ajax page does not respond and it times out. However, I cannot stress enough how this is not the way to do it, in fact its inviting a future disaster.
Ideally you should send a specific response back to the client, eg blank, or "0" or "NULL", and then in the client side code treat that response as a no response.
If you have no control over client side code eg, a bot, I would second Mark Baker's comment and say send a 444 or if you are feeling funny, 418 response :)
This post explains how to send a HTTP response code using PHP.
Client side timeout? Probably you want to end the user's session so you can simply use session_destroy()
before you die
or exit
your script.
Also it is weird that instead of redirecting the user with a notice, you are ending the script execution which is not friendly. If you want, you can use header()
to redirect the user to some page which may throw him a notice about what he did or why he was prevented/redirected.
Have the same problem. Need to not respond, nothing, just stop. Found nothing, and use:
posix_kill(posix_getpid(), 9);
It just kills php process. Not a god solution but works for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With