your elseif is always true.
An active connection will stay active with the server whatever happens.
Now, what I'm not sure to understand is the "IF response low".
Could you clarify ??
Are refering to response time ?
Is this HTTP or another protocol ??
I think your goal is find a keepalive that will bring the server down when you need it.
If you can find the right keepalive, the rest of your algorithm will be fine.
Gilles.