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

Kingsley Tart kingsley at skymarket.co.uk
Tue May 11 11:31:57 CDT 2010


On Wed, 2010-04-28 at 11:47 -0400, Fred Posner wrote:
> > 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.

Yes agreed but I don't know C. We are however planning to make this into
a daemon at some point to get around the Perl compiler overhead.

> 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);

This is essentially what we can do with the AGIwrap package, and for
debugging we can uncomment the "warn" line so that we can see what is
being set at call time. It was done this way because the scripts already
have many references to $AGI->set_variable(blah) so it was easier to put
a wrapper around the method call.


package Asterisk::AGIwrap;
use strict;
use base 'Asterisk::AGI';

sub set_variable
  {
    my ($self, %vars) = @_;
    while (my($var,$val) = each %vars)
      {
        if (!defined($val))
          { warn "AGI->set_variable: not setting '$var' because value was undef\n"; next; }
        #warn "AGI->set_variable('$var','$val')\n";
        $self->SUPER::set_variable($var, $val);
      }
  }

Cheers,
Kingsley.




More information about the asterisk-users mailing list