Php - agi

Hi,

I start my first AGI - PHP. Nothing is working and I have no idea why.
I took this example from a book

I am using : Asterisk 1.4.26 on CentOS v 5.3
I install php-cli

Here is my config

---------------- extensions.conf
exten => 560,1,Answer()
exten => 560,2,wait(0.5)
exten => 560,3,AGI(helloworld.php)
exten => 560,4,hangup()

and my /car/lib/asterisk/bin-agi/helloword/php

#!/usr/bin/php -q

<? ob_implicit_flush(false); set_time_limit(6); $stdin = fopen([php://stdin](php://stdin), r); $stdlog = fopen(my_agi.log, w); $debug = false; /* Read input from Asterisk and output via $astOutput */ function astRead() { global $stdin, $debug, $stdlog; $astOutput = str_replace("\n", "", fgets($stdin, 4096)); if ($debug) fputs($stdlog, "read: $input\n"); return $astOutput ; } /* Write AGI command to Asterisk */ function astWrite($agiCommand) { global $debug, $stdlog; if ($debug) fputs($stdlog, "write: $agiCommand\n"); echo $agiCommand."\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; } } /* Operational Code starts here */ /* Playback the demo-congrats.gsm file from the * directory /var/lib/asterisk/sounds/ */ /* Finalization of AGI script and clean-ups */ fclose ($stdin); fclose ($stdlog); exit(0); ?>

The result that I’ve got :

– Executing [560@default:1] Answer(“SIP/1000-086db980”, “”) in new stack
– Executing [560@default:2] Wait(“SIP/1000-086db980”, “0.5”) in new stack
– Executing [560@default:3] AGI(“SIP/1000-086db980”, “helloworld.php”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/helloworld.php
AGI Tx >> agi_request: helloworld.php
AGI Tx >> agi_channel: SIP/1000-086db980
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1252666765.13
AGI Tx >> agi_callerid: 1000
AGI Tx >> agi_calleridname: 1000
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 560
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: default
AGI Tx >> agi_extension: 560
AGI Tx >> agi_priority: 3
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >>
AGI Rx << Usage: php [options] [-f] [–] [args…]
AGI Tx >> 510 Invalid or unknown command
AGI Rx << php [options] -r [–] [args…]
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << php [options] [-B <begin_code>] -R [-E <end_code>] [–] [args…]
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << php [options] [-B <begin_code>] -F [-E <end_code>] [–] [args…]
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << php [options] – [args…]
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << php [options] -a
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx <<
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -a Run interactively
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -c | Look for php.ini file in this directory
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -n No php.ini file will be used
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -d foo[=bar] Define INI entry foo with value 'bar’
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -e Generate extended information for debugger/profiler
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -f Parse .
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -h This help
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -i PHP information
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -l Syntax check only (lint)
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -m Show compiled in modules
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -r Run PHP without using script tags <?..?>
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -B <begin_code> Run PHP <begin_code> before processing input lines
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -R Run PHP for every input line
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -F Parse and execute for every input line
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -E <end_code> Run PHP <end_code> after processing all input lines
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -H Hide any passed arguments from external tools.
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -s Display colour syntax highlighted source.
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -v Version number
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -w Display source with stripped comments and whitespace.
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << -z Load Zend extension .
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx <<
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << args… Arguments passed to script. Use – args when first argument
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << starts with - or script is read from stdin
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx <<
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << --rf Show information about function .
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << --rc Show information about class .
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx << --re Show information about extension .
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
AGI Rx <<
AGI Tx >> 510 Invalid or unknown command
[Sep 11 11:59:25] ERROR[3785]: utils.c:966 ast_carefulwrite: write() returned error: Broken pipe
– AGI Script helloworld.php completed, returning 0
– Executing [560@default:4] Hangup(“SIP/1000-086db980”, “”) in new stack
== Spawn extension (default, 560, 4) exited non-zero on 'SIP/100


Any idea what is the problem ?

Thanks

Any Idea ??
Thanks

You have to use some examples - there are a lot of working examples over Internet.
As I see in a2billing.php, they start with:

[code]#!/usr/bin/php -q

<?php [/code] and you start with: [code]#!/usr/bin/php -q <? [/code]