Debugging PHP Originate via AMI

Hi folks. I’ve recently integrated some basic AMI functionality into a PHP site I’ve developed on our Intranet that pulls data from the asterisk CDR database to allow us to track incoming calls and file call notes against them. I’ve used examples from https://www.voip-info.org/asterisk-manager-example-php/ to create a call button next to each incoming call will use the AMI Originate action to connect a call between a selected device and that number.

My problem is this works amazingly most of the time … but then sometimes fails for reasons I can’t seem to work out. And the thing that’s really getting me is I can’t seem to get any info to debug this with. I can connect to an AMI session via telnet and when things are working I see information about the successful call. But when it fails NOTHING shows up in the AMI session. In the asterisk console I just see:

Manager 'phpscript' logged on from 127.0.0.1
Manager 'phpscript' logged off from 127.0.0.1

I have to manually type into an AMI login what my script would have sent to Asterisk to see any error information. I’m sending this (which was working earlier today):

Action: Originate
Channel: SIP/my-sip-device
Context: office
Exten: 600
Priority: 1

And I get this:

Response: Error
Message: Originate failed

So I have two questions: First and probably most important is how can I get these error messages from my PHP script to help me track down problems in future. Second, why might this be failing when it has been working?

Any help appreciated!

Okay it looks like I may have solved part of the mystery. Seems I’ve got some kind of network trouble today that is causing all my devices to be listed as UNREACHABLE when I do “sip show peers”

If anyone has answers to my first question - which is how to trace those AMI responses in my PHP script - I’d still appreciate any guidance.

It could be that the script is stalling on the Originate – try adding to it:

Async: yes

Thanks, I’ve added that to the script and we’ll see how it goes.

Before this thread gets locked… Any luck ?

No luck. Added the Async line as suggested. Still randomly fails to initiate the call. Success rate is approximately 50%. I’ve just accepted that sometimes I’ll need to click the call button in my page twice.

I just tried putting all that the commands, including the logon and logoff, that my PHP script is meant to write to the AMI in a text file and piping it through netcat. That works 100% of the time.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.