Use is_ressource function in close() and keepAlive() methods : this allows infinite loop to stop when close() is called