[asterisk-users] AGI perl script set timeout within script?

Tilghman Lesher tlesher at digium.com
Thu Jan 7 19:56:24 CST 2010


On Thursday 07 January 2010 18:59:24 David Backeberg wrote:
> On Thu, Jan 7, 2010 at 6:27 PM, JR Richardson <jmr.richardson at gmail.com> 
wrote:
> > problem I'm running into is if the DNS server is not responding, the
> > script hangs and waits for 30 seconds before returning to the Asterisk
> > dialplan.  I would like a timeout of 1 second, then return.
>
> A few things...
>
> * stop using DNS? Problem solved.
> * put nagios monitoring on your DNS server?
> * put in a second DNS server, and tune your DNS timeout to a very low
> value in /etc/resolv.conf (read the man page) before jumping to next
> server?
>
> Or you could use the Perl language feature, which is called 'alarm'.
> Google around for some code samples.

Ah, but Perl isn't actually doing the DNS lookup.  If you examine his script,
he's merely passing back a name to the Asterisk process, which is then calling
inet_aton(), which is the reason why he cannot control it from within the
script.  What he'd actually need to do is to start using Net::DNS to do the
resolution on that name, first, perhaps even going as far as to connect to the
server himself, and relay the channel between the AGI interface and the remote
TCP interface.

Then, he could use alarm() or the Time::Hires module to ensure his own
timeouts override the builtins.  But as it stands now, it's all Asterisk.

-- 
Tilghman Lesher
Digium, Inc. | Senior Software Developer
twitter: Corydon76 | IRC: Corydon76-dig (Freenode)
Check us out at: www.digium.com & www.asterisk.org



More information about the asterisk-users mailing list