Asterisk 1.4 php agi not working

Hi, Im having the simple AGI script, when incoming call is answered run script. But does not working. How can i run my script correctly?

By the way sorry for my english.

Here’s code:

extensions_additional.conf

[macro-auto-blkvm]

include => macro-auto-blkvm-custom

exten => s,1,Set(__MACRO_RESULT=)

exten => s,n,DBDel(${BLKVM_OVERRIDE})

exten => s,n,AGI(call-answered.agi,${CALLERID(ANI)},${CHANNEL})

call-answered.php:

#!/usr/bin/php -q
<?php
include("phpagi.php");
$agi = new AGI();
$agi->verbose("------------------------------------------");
$ani = $agi->request['agi_callerid'];
$agi->noop("My CalleID: <<<<<<<=".$ani);

$user = 'root';
$pass = 'eLaStIx.2oo7';
$db = new PDO('mysql:host=localhost;dbname=call', $user, $pass);

$query = $db->prepare("INSERT INTO deneme SET
gsm = ?,
agent = ?");
$insert = $query->execute(array("123123", "213123"));


execute: 

-- SIP/103-0000000e answered Local/103@from-internal-3556,2
-- Executing [s@macro-auto-blkvm:1] Set("SIP/103-0000000e", "__MACRO_RESULT=") in new stack
-- Executing [s@macro-auto-blkvm:2] Set("SIP/103-0000000e", "CFIGNORE=") in new stack
-- Executing [s@macro-auto-blkvm:3] Set("SIP/103-0000000e", "MASTER_CHANNEL(CFIGNORE)=") in new stack
-- Executing [s@macro-auto-blkvm:4] Set("SIP/103-0000000e", "FORWARD_CONTEXT=from-internal") in new stack
-- Executing [s@macro-auto-blkvm:5] Set("SIP/103-0000000e", "MASTER_CHANNEL(FORWARD_CONTEXT)=from-internal") in new stack
-- Executing [s@macro-auto-blkvm:6] Macro("SIP/103-0000000e", "blkvm-clr|") in new stack
-- Executing [s@macro-auto-blkvm:7] AGI("SIP/103-0000000e", "call-answered.agi|*******|SIP/103-0000000e") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/call-answered.agi
AGI Tx >> agi_request: call-answered.agi
AGI Tx >> agi_channel: SIP/103-0000000e
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1481798039.22
AGI Tx >> agi_callerid: 103
AGI Tx >> agi_calleridname: unknown
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: unknown
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: macro-auto-blkvm
AGI Tx >> agi_extension: s
AGI Tx >> agi_priority: 7
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >>
-- AGI Script call-answered.agi completed, returning 0
-- Executing [s@macro-auto-blkvm:8] ExecIf("SIP/103-0000000e", "0?Set(MASTER_CHANNEL(CONNECTEDLINE(num))=103)") in new stack
== Spawn extension (macro-auto-blkvm, s, 8) exited non-zero on 'SIP/103-0000000e' in macro 'auto-blkvm'
-- Local/103@from-internal-3556,1 answered SIP/103-0000000d
-- Stopped music on hold on SIP/**-0000000d

Thanks

Note: Asterisk 1.4 isn’t just a little out of date. It’s extremely out of date. I’d highly recommend upgrading to a supported version of Asterisk.

All of that being said: what does the Asterisk CLI show when it attempts to execute the AGI script? Typically, failure to execute an AGI script is a path or permissions problem.

thanks but not permissions or path.
CLI:
execute:

-- SIP/103-0000000e answered Local/103@from-internal-3556,2
-- Executing [s@macro-auto-blkvm:1] Set("SIP/103-0000000e", "__MACRO_RESULT=") in new stack
-- Executing [s@macro-auto-blkvm:2] Set("SIP/103-0000000e", "CFIGNORE=") in new stack
-- Executing [s@macro-auto-blkvm:3] Set("SIP/103-0000000e", "MASTER_CHANNEL(CFIGNORE)=") in new stack
-- Executing [s@macro-auto-blkvm:4] Set("SIP/103-0000000e", "FORWARD_CONTEXT=from-internal") in new stack
-- Executing [s@macro-auto-blkvm:5] Set("SIP/103-0000000e", "MASTER_CHANNEL(FORWARD_CONTEXT)=from-internal") in new stack
-- Executing [s@macro-auto-blkvm:6] Macro("SIP/103-0000000e", "blkvm-clr|") in new stack
-- Executing [s@macro-auto-blkvm:7] AGI("SIP/103-0000000e", "call-answered.agi|*******|SIP/103-0000000e") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/call-answered.agi
AGI Tx >> agi_request: call-answered.agi
AGI Tx >> agi_channel: SIP/103-0000000e
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1481798039.22
AGI Tx >> agi_callerid: 103
AGI Tx >> agi_calleridname: unknown
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: unknown
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: macro-auto-blkvm
AGI Tx >> agi_extension: s
AGI Tx >> agi_priority: 7
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >>
 ****AGI Script call-answered.agi completed, returning 0**
-- Executing [s@macro-auto-blkvm:8] ExecIf("SIP/103-0000000e", "0?Set(MASTER_CHANNEL(CONNECTEDLINE(num))=103)") in new stack
== Spawn extension (macro-auto-blkvm, s, 8) exited non-zero on 'SIP/103-0000000e' in macro 'auto-blkvm'
-- Local/103@from-internal-3556,1 answered SIP/103-0000000d
-- Stopped music on hold on SIP/**-0000000d

From that output, it appears that from Asterisk’s perspective, the AGI script executed. Assuming that your script didn’t actually do what you wanted it to do - which is hard to tell from this - then I would suspect your issue is in one of the following areas:

  1. The AGI library you’re using has a bug in it. There’s no evidence necessarily to suggest that’s the case - so it’s unlikely, but possible.

  2. The Asterisk version you’re using has a bug in it. The version you’re using is ancient, but the AGI code hasn’t changed much between versions. So again it’s unlikely, but possible.

  3. Your code has a bug in it and/or is not executing as you would expect. You could simulate Asterisk’s launching of your script by using an exec from a bash script, and piping stdin to the launched PHP script.