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

Steve Edwards asterisk.org at sedwards.com
Thu Jan 7 18:09:53 CST 2010


On Thu, 7 Jan 2010, JR Richardson wrote:

> I'm running an AGI, calling a perl script the does number lookups to a 
> remote server.  I would like to put a timeout in the script.  The 
> 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.

I'm a C weenie, so I can't provide Perl code. But it should look something 
like this:

// handle the alarm
static	void				lookup_failed
 	(
 	  void
 	)
 	{
 	exit(EXIT_FAILURE);
 	}

int					main
 	(
 	)

 	...

// set a signal alarm handler
 	signal(SIGALRM, (void (*)(int))(int)lookup_failed);

// set the alarm to go off in 1 second
 	alarm(1);

// lookup my number
 	do_lookup(dnis);

// cancel the alarm
 	alarm(0);

 	...

Of course, solving the real issue (DNS lookups), or masking it with a 
local caching server or even a /etc/hosts file are viable alternatives.

-- 
Thanks in advance,
-------------------------------------------------------------------------
Steve Edwards       sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                              Fax: +1-760-731-3000



More information about the asterisk-users mailing list