problem with running phpagi from asterisk

General and Support topics relating to ViciDialNow and GoAutoDial ISO installers

Moderators: enjay, williamconley, Op3r, Staydog, gardo, mflorell, MJCoate, mcargile, Kumba, s0lid

problem with running phpagi from asterisk

Postby iftekhar » Tue Aug 09, 2011 7:54 pm

Hi, I want to run a "php agi" file from asterisk dialplan. I want, when someone calls 777001 then a php agi file named "helloworld.php" will be invoked and he should listen to a simple IVR which I wrote inside the "helloworld.php". But when I dial 777001 it shows me an error message telling

"ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe" and hangs up.


The status of cli when I call 777001 is:

-- Executing [777001@trunkinbound:1] Answer("SIP/carrier1-00000000", "") in new stack
-- Executing [777001@trunkinbound:2] Wait("SIP/carrier1-00000000", "0.5") in new stack
-- Executing [777001@trunkinbound:3] AGI("SIP/carrier1-00000000", "helloworld.php") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/helloworld.php
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
[Aug 10 05:45:40] ERROR[25483]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
-- AGI Script helloworld.php completed, returning 0
-- Executing [777001@trunkinbound:4] Hangup("SIP/carrier1-00000000", "") in new stack
== Spawn extension (trunkinbound, 777001, 4) exited non-zero on 'SIP/carrier1-00000000'




Here is my "helloworld.php" file:

#!/usr/bin/php -q
<?
ob_implicit_flush(false);
set_time_limit(6);

$stdin = fopen(‘php://stdin’, ‘r’);
$stdlog = fopen(‘my_agi.log’, ‘w’);

$debug = false;

function astRead() {
global $in, $debug;
$input = str_replace("\n", "", fgets($in, 4096));
if ($debug) echo "VERBOSE \"read: $input\"\n";
return $input;
}

function astWrite($line) {
global $debug;
if ($debug) echo "VERBOSE \"write: $line\"\n";
print $line."\n";
}


/* Handling execution input from Asterisk */
$agivar = array();
while (!feof($stdin))
{
$temp = fgets($stdin);
$temp = str_replace("n","",$temp);
$s = explode(":",$temp);
$agivar[$s[0]] = trim($s[1]);
if ($temp == "")
{
break;
}
}



/* Say the number 123456 */
astWrite("SAY NUMBER 123456 #");
astRead();

/* Finalization of AGI script and clean-ups */

fclose ($stdin);
fclose ($stdlog);
exit(0);

?>




Note: I have create a file named "my_agi.log" in the directory "/var/lib/asterisk/agi-bin" and changed the permission to both helloworld.php and my_agi.log to 755 and 777 both.



Here is my extension settings for helloworld.php in the extension.conf:

[trunkinbound]

exten => 777001,1,Answer
exten => 777001,n,Wait(0.5)
exten => 777001,n,AGI(helloworld.php)
exten => 777001,n,Hangup()




Can vicidial guys tell me where is the problem?

_____________________

Installer : GoAutoDial CE 2.1

Astguiclient VERSION: 2.4-309a
BUILD: 110430-1642

Kernel VERSION: 2.6.18-238.9.1.el5.goPAE
BUILD: 100510-2015
Asterisk: 1.4.39.1-vici
CentOS release 5.6 32 bit
[/b]
iftekhar
 
Posts: 14
Joined: Thu Jul 28, 2011 12:30 am

Postby williamconley » Tue Aug 09, 2011 8:40 pm

I have an idea. Take a STOCK agi script from somewhere on an asterisk site and use it verbatim. When you get that to work, then slowly modify it to work the way you like.

This exercise has been worked out 100 times, and always comes down to: Don't Try To Figure It All Out At Once. The world of Open Source is brilliant ... IF you can learn to start with what someone else has working, and move on from there. But do NOT change it before you "move on" until after you have it working verbatim.

http://astbook.asteriskdocs.org/en/2nd_ ... ECT-3.html
Vicidial Installation and Repair, plus Hosting and Colocation
Newest Product: Vicidial Agent Only Beep - Beta
http://www.PoundTeam.com # 352-269-0000 # +44(203) 769-2294
williamconley
 
Posts: 20258
Joined: Wed Oct 31, 2007 4:17 pm
Location: Davenport, FL (By Disney!)


Return to ViciDialNow - GoAutoDial

Who is online

Users browsing this forum: Google [Bot] and 68 guests