AGI not working

Hi everyone,
I’m learning using AGI. I created a very very simple php file:

#! /usr/bin/php -q

<?php require("/var/lib/asterisk/agi-bin/phpagi.php"); set_time_limit(30); error_reporting(E-ALL); $agi = new AGI(); $agi->answer(); $agi->exec_dial("SIP","201"); $agi->stream_file('demo-congrats','123'); $agi->hangup(); ?>

.It did work and I got error like this:

[Oct 13 16:21:57] VERBOSE[3187] logger.c: == Parsing ‘/etc/asterisk/manager.conf’: [Oct 13 16:21:57] VERBOSE[3187] logger.c: Found
[Oct 13 16:21:57] VERBOSE[3187] logger.c: == Parsing ‘/etc/asterisk/manager_additional.conf’: [Oct 13 16:21:57] VERBOSE[3187] logger.c: Found
[Oct 13 16:21:57] VERBOSE[3187] logger.c: == Parsing ‘/etc/asterisk/manager_custom.conf’: [Oct 13 16:21:57] VERBOSE[3187] logger.c: Found
[Oct 13 16:21:57] VERBOSE[3187] logger.c: == Manager ‘admin’ logged on from 127.0.0.1
[Oct 13 16:21:58] VERBOSE[3187] logger.c: == Manager ‘admin’ logged off from 127.0.0.1
[Oct 13 16:22:05] VERBOSE[3192] logger.c: – Executing [[email protected]:1] Answer(“SIP/208-0894e688”, “”) in new stack
[Oct 13 16:22:05] VERBOSE[3192] logger.c: – Executing [[email protected]:2] Festival(“SIP/208-0894e688”, “Hello”) in new stack
[Oct 13 16:22:05] VERBOSE[3192] logger.c: == Parsing ‘/etc/asterisk/festival.conf’: [Oct 13 16:22:05] VERBOSE[3192] logger.c: Found
[Oct 13 16:22:05] DEBUG[3192] app_festival.c: Text passed to festival server : Hello
[Oct 13 16:22:05] DEBUG[3192] app_festival.c: Passing text to festival…
[Oct 13 16:22:05] DEBUG[3192] app_festival.c: Passing data to channel…
[Oct 13 16:22:05] DEBUG[3192] app_festival.c: Festival WV command
[Oct 13 16:22:05] ERROR[3192] channel.c: ast_read() called with no recorded file descriptor.
[Oct 13 16:22:06] DEBUG[3192] app_festival.c: Last frame
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Executing [[email protected]:3] AGI(“SIP/208-0894e688”, “simpleAgi.php”) in new stack
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Launched AGI Script /var/lib/asterisk/agi-bin/simpleAgi.php
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] ERROR[3192] utils.c: write() returned error: Broken pipe
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – AGI Script simpleAgi.php completed, returning 0
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Executing [[email protected]:4] Hangup(“SIP/208-0894e688”, “”) in new stack
[Oct 13 16:22:06] VERBOSE[3192] logger.c: == Spawn extension (from-internal, 789, 4) exited non-zero on ‘SIP/208-0894e688’
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Executing [[email protected]:1] Macro(“SIP/208-0894e688”, “hangupcall”) in new stack
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Executing [[email protected]:1] GotoIf(“SIP/208-0894e688”, “1?skiprg”) in new stack
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Goto (macro-hangupcall,s,4)
[Oct 13 16:22:06] DEBUG[3192] app_macro.c: Executed application: GotoIf
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Executing [[email protected]:4] GotoIf(“SIP/208-0894e688”, “1?skipblkvm”) in new stack
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Goto (macro-hangupcall,s,7)
[Oct 13 16:22:06] DEBUG[3192] app_macro.c: Executed application: GotoIf
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Executing [[email protected]:7] GotoIf(“SIP/208-0894e688”, “1?theend”) in new stack
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Goto (macro-hangupcall,s,9)
[Oct 13 16:22:06] DEBUG[3192] app_macro.c: Executed application: GotoIf
[Oct 13 16:22:06] VERBOSE[3192] logger.c: – Executing [[email protected]:9] Hangup(“SIP/208-0894e688”, “”) in new stack
[Oct 13 16:22:06] VERBOSE[3192] logger.c: == Spawn extension (macro-hangupcall, s, 9) exited non-zero on ‘SIP/208-0894e688’ in macro ‘hangupcall’
[Oct 13 16:22:06] VERBOSE[3192] logger.c: == Spawn extension (from-internal, h, 1) exited non-zero on ‘SIP/208-0894e688’
[Oct 13 16:22:09] NOTICE[2935] chan_sip.c: Registration from ‘sip:[email protected]’ failed for ‘172.25.2.41’ - No matching peer found
[Oct 13 16:22:10] NOTICE[2935] chan_sip.c: Registration from ‘sip:[email protected]’ failed for ‘172.25.2.41’ - No matching peer found
[Oct 13 16:22:10] NOTICE[2935] chan_sip.c: Registration from ‘sip:[email protected]’ failed for ‘172.25.2.41’ - No matching peer found
[Oct 13 16:22:10] NOTICE[2935] chan_sip.c: Registration from ‘sip:[email protected]’ failed for ‘172.25.2.41’ - No matching peer found
[Oct 13 16:22:10] NOTICE[2935] chan_sip.c: Registration from ‘sip:[email protected]’ failed for ‘172.25.2.41’ - No matching peer found
[Oct 13 16:22:10] NOTICE[2935] chan_sip.c: Registration from ‘sip:[email protected]’ failed for ‘172.25.2.41’ - No matching peer found
[Oct 13 16:22:11] VERBOSE[3196] logger.c: == Parsing ‘/etc/asterisk/manager.conf’: [Oct 13 16:22:11] VERBOSE[3196] logger.c: Found
[Oct 13 16:22:11] VERBOSE[3196] logger.c: == Parsing ‘/etc/asterisk/manager_additional.conf’: [Oct 13 16:22:11] VERBOSE[3196] logger.c: Found
[Oct 13 16:22:11] VERBOSE[3196] logger.c: == Parsing ‘/etc/asterisk/manager_custom.conf’: [Oct 13 16:22:11] VERBOSE[3196] logger.c: Found
[Oct 13 16:22:11] VERBOSE[3196] logger.c: == Manager ‘admin’ logged on from 127.0.0.1

Here is my very simple dial plan:

[from-internal]
exten => 789,1,Answer()
exten => 789,n,Festival(Hello)
exten => 789,n,AGI(simpleAgi.php)
exten => 789,n,Hangup()

Could you please help me? It took me a day trying to figure out the problem is search help on internet but I got no luck.
Please help!
Thanks in advance,

The problem was solved.
I installed a latest version of Asterisk to another machine, the AGI worked. I copied phpagi.php file from the new system to the old system, the old system worked too. So, the problem is the phpagi.php in the previous version, which is Asterisk 2.5x, was broken.

Thank you,
I’m running FreePBX 2.6.0.2.
I am doing at what you instruct above. I’ll let you know everything after I’m done with that.
Thank you so much!
Dan

Hi,
I got the same error:

[Oct 15 11:32:39] VERBOSE[3307] logger.c: – Launched AGI Script /var/lib/asterisk/agi-bin/simpleAgi.php
[Oct 15 11:32:39] ERROR[3307] utils.c: write() returned error: Broken pipe

with only codes:

#!/usr/bin/php -q

<?php
(nothing here)
?>

Do you think that this is a freePBX bug?
I’m using AsteriskNOW with FreePBX 2.6.
Thank you!

try some troubleshooting 101:

take simpleAgi and take all the php code out i.e. leave in just

#!/usr/bin/php -q] and the PHP brackets

run and see if you get broken pipe errors.

then add the first php line of code:

require(…)

try running again.

Just googling this error “utils.c: write() returned error: Broken pipe” show a lot of incidents many of which seem to be related to phpagi.php itself [either corrupt or mismatched with the version of asterisk] so try to figure out where the error is coming from. What asterisk and freePBX are you running? Tell me its not trixbox.

having seen the error over and over, you might stop with the posting of the whole log segment unless there is something new to show us.

I don’t know how to fix this problem. I still got a bunch of error like this:

[Oct 15 09:53:00] VERBOSE[2621] logger.c: – Launched AGI Script /var/lib/asterisk/agi-bin/simpleAgi.php
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] ERROR[2621] utils.c: write() returned error: Broken pipe
[Oct 15 09:53:00] VERBOSE[2621] logger.c: – AGI Script simpleAgi.php completed, returning 0
[Oct 15 09:53:00] VERBOSE[2621] logger.c: – Executing [[email protected]:2] NoCDR(“SIP/208-08d5b5a8”, “”) in new stack
[Oct 15 09:53:00] VERBOSE[2621] logger.c: – Executing [[email protected]:3] Wait(“SIP/208-08d5b5a8”, “1”) in new stack
[Oct 15 09:53:01] VERBOSE[2621] logger.c: – Executing [[email protected]:4] Playback(“SIP/208-08d5b5a8”, “silence/1&cannot-complete-as-dialed&check-number-dial-again|noanswer”) in new stack
[Oct 15 09:53:01] VERBOSE[2621] logger.c: – <SIP/208-08d5b5a8> Playing ‘silence/1’ (language ‘en’)
[Oct 15 09:53:02] VERBOSE[2621] logger.c: – <SIP/208-08d5b5a8> Playing ‘cannot-complete-as-dialed’ (language ‘en’)
[Oct 15 09:53:04] VERBOSE[2623] logger.c: == Parsing ‘/etc/asterisk/manager.conf’: [Oct 15 09:53:04] VERBOSE[2623] logger.c: Found

Please help!
Thanks

Well that does confirm what we discovered several msgs ago: its the first line of code that nukes it…or just the act of opening the file.

Its definitely not a freePBX bug.

Since freePBX forums have no private messaging capability, contact me directly if you want me to hop on and take a look for myself.

By the way, when I make call, I got nothing but a fast busy tone.
Thanks

what did you use to create the simpleAgi.php file?

everything is consistent with the first line of the script blowing up:

[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Rx << Usage: php [options] [-f] [–] [args…]
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> 510 Invalid or unknown command

no need to look or worry about anything else but that first line.

I use vi command to create the php file:
vi simpleAgi.php
then I added codes into it.

I fixed the first line already.

Thanks

you meant the first line in error message, right. I thought it’s the first line in the simpleAgi.php piece.
I am trying , trying … but nothing’s getting better.
Regards

i mean that it is blowing up at the first line of the simpleAgi file:

#!/usr/bin/php -q

have you got correct permissions and ownership on the file? is it executable by asterisk:asterisk ?

Yes, I did change permission for the file:
chown asterisk:asterisk simpleAgi.php

Thanks

Did I get the right file permission here:

-rwxrwxrwx 1 asterisk asterisk 328 Oct 14 15:07 simpleAgi.php

Thanks,

Hi,
I already did:
chmod 777 /var/lib/asterisk/agi-bin/simpleAgi.php
chown asterisk:asterisk /var/lib/asterisk/agi-bin/simpleAgi.php

Save and restart dialplan every time I changed it.

Thank you,

sorry for your pain.

the script is blowing up on the very first line:

#! /usr/bin/php -q

if you have include the entire script, it seems you have a few bits missing anyway.

the file contents should look something like:

#!/usr/bin/php -q

<?php require("/var/lib/asterisk/agi-bin/phpagi.php"); set_time_limit(30); error_reporting(E-ALL); $agi = new AGI(); $agi->answer(); $agi->exec_dial("SIP","201"); $agi->stream_file('demo-congrats','123'); $agi->hangup(); ?>

make sure you use a unix editor so you don’t get windows style new lines which will kill an agi script immediately.

argh…just realized this is not showing the code… so maybe you did have it correct …

this is better: http://pastebin.com/8MLy30KP

Hi mudslide,
I appreciated your help. But I still got no luck.
I run your your script and still have error:

[Oct 14 14:12:22] VERBOSE[24344] logger.c: – Executing [[email protected]:1] AGI(“SIP/211-09730db8”, “simpleAgi.php”) in new stack
[Oct 14 14:12:22] VERBOSE[24344] logger.c: – Launched AGI Script /var/lib/asterisk/agi-bin/simpleAgi.php
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_request: simpleAgi.php
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_channel: SIP/211-09730db8
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_language: en
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_type: SIP
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_uniqueid: 1287090742.47
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_callerid: 211
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_calleridname: device
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_callingpres: 0
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_callingani2: 0
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_callington: 0
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_callingtns: 0
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_dnid: 123
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_rdnis: unknown
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_context: from-internal
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_extension: 123
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_priority: 1
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_enhanced: 0.0
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> agi_accountcode:
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >>
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Rx << Usage: php [options] [-f] [–] [args…]
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> 510 Invalid or unknown command
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Rx << php [options] -r [–] [args…]
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> 510 Invalid or unknown command
[Oct 14 14:12:22] ERROR[24344] utils.c: write() returned error: Broken pipe
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Rx << php [options] [-B <begin_code>] -R [-E <end_code>] [–] [args…]
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> 510 Invalid or unknown command
[Oct 14 14:12:22] ERROR[24344] utils.c: write() returned error: Broken pipe
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Rx << php [options] [-B <begin_code>] -F [-E <end_code>] [–] [args…]
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> 510 Invalid or unknown command
[Oct 14 14:12:22] ERROR[24344] utils.c: write() returned error: Broken pipe
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Rx << php [options] – [args…]
[Oct 14 14:12:22] VERBOSE[24344] logger.c: AGI Tx >> 510 Invalid or unknown command


I am using asteriskNOW which is running on Centros Linux.
Thank you for your help.
Dan

if i am not mistaken, the sequence of events when you dial 789 is:

(1) Answer
(2) Say Hello
(3) Answer again

that does not seem that logical.