Is it possible to end an PHP process from within PHP, to make it seem on the client side that it stopped responding, from a users perspective not from a technical point of view.
This is not a solution:
<?php
die();
?>
The idea is there is a file that's being downloaded and I don't want it ever to complete. Possible solution:
<?php
sleep(1000000000000000); //Or any really large number
?>
The downside is that this process will stay alive on the server side and you probably don't want that to happen.
Short answer no.
The best way I've found of testing systems how they handle broken connections is to physically pull out network cables from their sockets.
To the question "Is it possible to end an PHP process from within PHP, to make it seem on the client side that it stopped responding" the answer is no. You won't be able to do that from within PHP, and I can't see how you could do that from outside PHP either.
If you have access to it and you're on a *nix system and have sufficient privileges, you could try killing the connection using a system call to tcpkill
. Get the user's IP address and port (the incoming request will be on port 80, but the user will be on a uniquely identifiable port) and then kill the connection. Something like this:
<?php
$remotehost = $_SERVER['REMOTE_ADDR'];
$remoteport = $_SERVER['REMOTE_PORT'];
$result = system("tcpkill host $remotehost port $remoteport");
echo($result ? "tcpkill worked" : "tcpkill didn't work");
?>
You could do the same thing with iptables, but I'd be real nervous about doing that. No better way to hose a box than ruining its firewall.
maybe exit();
?
Other than shooting down the running process as outlined in the comments (which is horrible!) another idea that comes to mind - I am assuming this is for testing purposes and you have full control over the server - is to execute a shell script that activates a firewall, switches off the network adapter, or does something else that brings network activity to a grinding halt immediately.
I don't know how long the client side will wait but this will hang for quite a while. It continually sends content for the browser to parse but the browser won't have anything to render.
<?php
set_time_limit(0);
while(true)
{
echo '<div></div>';
flush();
}
?>
As stated in your question, the down side is that the server will be running the script indefinitely. I presume that as soon as your script stops sending data, the browser isn't going to wait around.
精彩评论