Alexander Foken wrote:
http://search.cpan.org/src/CAPTTOFU/DBD-mysql-3.0007/dbdimp.c line 1309 and following, the value is converted to an int, then passed to mysql_options(), which is a part of the mysql API. (Ignore the cast to const char *, that's just how the mysql_options() API call is defined.) Looking at http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html , there IS NO WAY to specify a timeout of less than one second.

It seems that you have to live with a minimum timeout of one second, as alarm() also has only seconds resolution. The only way for a timeout of less than one second is a combination of fork(), select(), kill() and a custom signal handler, which is really, really ugly.

With Time::HiRes and Sys::Sigaction you could do something like:

use Time::HiRes qw (ualarm);
use Sys::SigAction qw (set_sig_handler);

eval {
    my h$ = set_sig_handler('ALRM', sub{die;},
                  {mask=>[qw(INT ALRM)],safe=>0);

    # set alarm to 500ms
    ualarm(500_000)

    # other stuff

    # reset alarm
    ualarm(0);
  }

I used something similar in some test code which worked as expected but I never used it in production.

Let's try to solve the problem in an other way: Why do you need such a short timeout?

Alexander

On 24.09.2006 12:23, Duncan Wren wrote:
I have looked at the code for DBD::mysql and DBI.pm but cannot workout where
the timeout is implemented or where the default is specified. Does anyone
know where this logic is implemented? I would rather make make the change in the module that currently implements the time out code than add some logic
to add timeout in my application code.

Duncan

On 24/09/06, Alexander Foken <[EMAIL PROTECTED]> wrote:

Without looking at the source code of DBD::mysql, I would quess that the
mysql_connect_timeout parameter is an integer. 0.5 is rounded down to 0,
which is the same as not specifying mysql_connect_timeout at all. If you
are on a Unix/POSIX System, alarm() and Signals may help.

Alexander

On 23.09.2006 18:02, Duncan Wren wrote:
> The DBI module when connecting to a mysql database seams to only support
> integer values for the mysql_connect_timeout if you use say 0.5 secs
> as the
> timeout value it defaults to 3secs. Does anyone know a way round this
> problem as i need a very short timeout in my application.
>
> for example
>
> #does not work and defaults to 3 secs timeout
> $dbh =
> DBI->connect("DBI:mysql:db_name:db_host:3306;mysql_connect_timeout=
> 0.5","username","password");
>
> #does work and timesout after 1 sec
> $dbh =
>
DBI->connect("DBI:mysql:db_name:db_host:3306;mysql_connect_timeout=1","username","password");
>
>
> Thanks
>
> Duncan
>


--
Alexander Foken
mailto:[EMAIL PROTECTED]  http://www.foken.de/alexander/







--
Stephen Carville <[EMAIL PROTECTED]>
Unix and Network Admin
Nationwide Totalflood
6033 W. Century Blvd
Los Angeles, CA 90045
310-342-3602

Reply via email to