[asterisk-users] Asterisk 1.4.30 is slow sending STDIN to AGI script

Fred Posner fred at teamforrest.com
Wed Apr 28 10:47:14 CDT 2010


On Apr 28, 2010, at 11:30 AM, Steve Edwards wrote:

> On Wed, 28 Apr 2010, Gareth Blades wrote:
> 
>> The script does not issue any commands. The same script is called at all 
>> 3 stages but with different parameters on the command line to indicate 
>> the call status. Works fine before the call is answered but during and 
>> at the end of the call it quits before asterisk has finished sending the 
>> information about the current call via STDIN.
> 
> As others have said -- you are violating the protocol.
> 
> Asterisk sends the "AGI environment" to the AGI via STDIN. If you don't 
> read it, you are violating the protocol.
> 
> For a AGI that is called repeatedly, maybe you should consider 
> implementing it in a compiled language.
> 
> You can execute XXX AGIs written in C in the time it takes to load the 
> Perl interpreter and parse your script.
> 
> -- 


Of course this will turn into a religious war ;)

Bottom line, if you like perl, use perl. Even though C is faster, there are benefits to using a language you know as well as implementing it for other reasons. I end up using perl 99% of the time just for simple ability with MySQL stored procedures or connecting ease with MSSQL databases. That being said...

Try starting your script with something such as:

$|=1;

while(<STDIN>) {
	chomp;
	last unless length($_);
}

(of course you can add whatever you want in there to pull the variables...

For setting multiple asterisk variables, I like using a sub:

sub setvariable {
	my ($variable, $value) = @_;
	print STDOUT "SET VARIABLE $variable \"$value\" \n";
	while(<STDIN>) {
		m/200 result=1/ && last;
	}
	return;
}

then just call it with something like:

&setvariable("MAILBOX", $mailbox);


--fred
http://qxork.com


More information about the asterisk-users mailing list