Understanding on phpagi

I would like to have a understandable documentation about phpagi. Have searched a lot but could not find it anywhere else complicated and vaguely described.

Does every phpagi script just maintain the agi commands or there are some functions and commands which are not directly an agi command but interpreted through phpagi and then pushed to asterisk?

So I would like to understand from an example, if someone could share it with me. Say for an example, if a customer calls, i have a dialplan which is like

Exten => 111,1,answer()
Same => here goes the agi
Same => n,hangup()

And i want to have a agi script which will just check a database and find that callers number in some row, and if it exists, the caller will be transfered to an IVR menu ‘xyz’. Otherwise the callers number will be registered(inserted) in some row of the database and hang up the call. Or maybe u can share just a very basic example from which I can understand.

Thanks!

Unfortunately, documentation is not as much fun to write as code, and most coders are not technical writers. Being able to explain clearly and consistently is a skill. A lot of coders will bail with a lame statement like ‘my code is self documenting so just read the code.’

I’m not sure I understand your question (and I’ve never used phpagi in a production application), but if you look at the source file phpagi.php, you will see that most of the functions are ‘wrappers’ around the AGI command. For example:

    function get_data($filename, $timeout=NULL, $max_digits=NULL)
    {
        return $this->evaluate(rtrim("GET DATA $filename $timeout $max_digits"));
    }

(The author(s) of phpagi also include functions to use ‘festival’ and ‘text2wav’ which are not AGI features.)

The purpose of an AGI library (I wrote one in C), is to implement the AGI protocol (send a request to Asterisk, read and parse the response) to reduce repetitive code and ease the coding of the AGI.

You don’t need to use an AGI library. You could issue the request (fwrite), read the response (fgets), and parse the response every single time, but it gets laborious and prone to errors.

Also, most programmers don’t grasp the significance of ‘write a line, read a line’ and their code will break the AGI protocol resulting in inconsistent execution or unexplained failures.

Using a library is a really good idea.

Also, observing the interaction between Asterisk and your AGI from the console with ‘agi set debug on’ will help with understanding what is going on and why things fail.

1 Like

Thank you Edward! Very much informative and clean!