Reducing the timeout on a TCP connection

Bill Moran wmoran at collaborativefusion.com
Tue Aug 1 21:25:13 UTC 2006


In response to Philip Hallstrom <freebsd at philip.pjkh.com>:

> > I'm writing some monitoring scripts, and I'm having some trouble because
> > the TCP seems to wait 90 seconds before giving up on initiating a
> > connection.
> >
> > (The script is in PHP, testing a PostgreSQL database.  Neither PHP nor
> > libpq (which PHP's PostgreSQL support is based on) seem to have any
> > settings that can be used to adjust this timeout).
> 
> http://www.php.net/fsockopen
> 
> Last parameter is a timeout value... I'd imagine the other socket calls 
> have something similar... whether or not it's honored I dunno, but it is 
> there.
> 
> Although maybe i'm misunderstanding the question.

Thanks, Philip.  Between your and Ted's advice, I've decided to do a three-
tiered test.  

1) I test to see if I can establish a socket with fsockopen, with a fairly
   short timeout.  This gives me a quick response in the event of a total
   failure that takes the server offline.
2) I then test using pg_connect() which has (apparently) a 90s timeout,
   but gives me more thorough testing in case PG is running, but
   misbehaving.
3) Finally I execute a simple but telling SQL query that will give me a
   cursory feel for whether the data in the datbase is healthy.

This gives me a lot of config values for various timeouts and the ability
to check for several scenarios (from total HW failure, to PostgreSQL going
bonkers) with configurable reaction times.  Further testing should help me
to understand what numbers make good timeouts for the various stages.

-- 
Bill Moran
Collaborative Fusion Inc.


More information about the freebsd-questions mailing list