You could use gettimeofday() from Time::HiRes to measure the time between sending and receiving data. That being said, I think a single large timeout value is better than making a variable timeout. Just because a server was quick to respond earlier doesn't mean it will be quick to respond later.