Php-agi 510 invalid or unknown command

Extension ‘/var/lib/asterisk/agi-bin/index.php’ not present.
510 Invalid or unknown command

:blush:

“I am getting this error while I execute my php-agi script
I have removed windows newline character after the shebang line.
Asterisk version I am using is - 1.6
php version - 5.2.0

my index.php file is :

#!/usr/bin/php -q

<?php set_time_limit(30); error_reporting(E_ALL); require_once 'phpagi.php'; $agi = new AGI(); $agi->stream_file("demo-congrats","#"); ?>

I am running asterisk with Dahdi on centos 6.3”

May be this issue is arising because of the version difference between asterisk and php. Please help me out

Most likely a permissions (including possibly SELINUX) problem.

Thanks David,

SElinux is already Disabled

Check the full path of php with this command

on linux run the command which php

and make sure that is the same on
#!/usr/bin/php -q

Is my php version fine? I am using 5.2.0

Previously I installed 5.3.3 but there was same problem with it so I installed ver 5.2 but no luck :frowning:

Run from the Linux Shell your script. First with: php index.php. Then do a chmod +x index.php and finally run with ./index.php

If there are php errors you will see it. If the script run you will see only the prompt until you press enter twice. Finally you have phpagi there right?

Thanks Navaismo…

yes I have phpagi right there in the same directory.

I think this is the issue

I did chmod +x index.php and then ./index.php
It shows Extension ‘./index.php’ not present.

What should I do?

Which version of phpagi are you using?

Its version 2

Solved!!!

I just did #dos2unix index.php

And the error was removed!!
Now I am facing another issue. My agi script loads but does not execute completely as it shows no output at the console. Here is the output:

– Requested transfer capability: 0x00 - SPEECH
– Executing [47673501@test:1] Answer(“DAHDI/i1/8802865008-5”, “”) in new stack
– Executing [47673501@test:2] Ringing(“DAHDI/i1/8802865008-5”, “”) in new stack
– Executing [47673501@test:3] Wait(“DAHDI/i1/8802865008-5”, “2”) in new stack
– Executing [47673501@test:4] AGI(“DAHDI/i1/8802865008-5”, “index.php”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/index.php
<DAHDI/i1/8802865008-5>AGI Tx >> agi_request: index.php
<DAHDI/i1/8802865008-5>AGI Tx >> agi_channel: DAHDI/i1/8802865008-5
<DAHDI/i1/8802865008-5>AGI Tx >> agi_language: en
<DAHDI/i1/8802865008-5>AGI Tx >> agi_type: DAHDI
<DAHDI/i1/8802865008-5>AGI Tx >> agi_uniqueid: 1360306869.4
<DAHDI/i1/8802865008-5>AGI Tx >> agi_version: 1.8.20.1
<DAHDI/i1/8802865008-5>AGI Tx >> agi_callerid: unknown
<DAHDI/i1/8802865008-5>AGI Tx >> agi_calleridname: unknown
<DAHDI/i1/8802865008-5>AGI Tx >> agi_callingpres: 0
<DAHDI/i1/8802865008-5>AGI Tx >> agi_callingani2: 0
<DAHDI/i1/8802865008-5>AGI Tx >> agi_callington: 0
<DAHDI/i1/8802865008-5>AGI Tx >> agi_callingtns: 0
<DAHDI/i1/8802865008-5>AGI Tx >> agi_dnid: unknown
<DAHDI/i1/8802865008-5>AGI Tx >> agi_rdnis: unknown
<DAHDI/i1/8802865008-5>AGI Tx >> agi_context: test
<DAHDI/i1/8802865008-5>AGI Tx >> agi_extension: 47673501
<DAHDI/i1/8802865008-5>AGI Tx >> agi_priority: 4
<DAHDI/i1/8802865008-5>AGI Tx >> agi_enhanced: 0.0
<DAHDI/i1/8802865008-5>AGI Tx >> agi_accountcode:
<DAHDI/i1/8802865008-5>AGI Tx >> agi_threadid: 140017133172480
<DAHDI/i1/8802865008-5>AGI Tx >>
– <DAHDI/i1/8802865008-5>AGI Script index.php completed, returning 0
– Executing [47673501@test:5] Hangup(“DAHDI/i1/8802865008-5”, “”) in new stack
== Spawn extension (test, 47673501, 5) exited non-zero on ‘DAHDI/i1/8802865008-5’
– Hungup ‘DAHDI/i1/8802865008-5’

This is my simple agi script:

#!/usr/bin/php -q

<?php set_time_limit(30); error_reporting(0); require('phpagi.php'); $agi = new AGI(); $agi->stream_file("demo-congrats","#"); $agi->hangup(); ?>

I have testes your code with PHP 5.4.11 on Fedora 17, The PHPAGI version is 2.20.
Here is the output:

== Using SIP VIDEO CoS mark 6 == Using SIP RTP CoS mark 5 -- Executing [62@phones:1] Answer("SIP/5000-00000001", "") in new stack -- Executing [62@phones:2] AGI("SIP/5000-00000001", "index.php") in new stack -- Launched AGI Script /var/lib/asterisk/agi-bin/index.php <SIP/5000-00000001>AGI Tx >> agi_request: index.php <SIP/5000-00000001>AGI Tx >> agi_channel: SIP/5000-00000001 <SIP/5000-00000001>AGI Tx >> agi_language: es <SIP/5000-00000001>AGI Tx >> agi_type: SIP <SIP/5000-00000001>AGI Tx >> agi_uniqueid: 1360350678.1 <SIP/5000-00000001>AGI Tx >> agi_version: 11.2.0 <SIP/5000-00000001>AGI Tx >> agi_callerid: 5000 <SIP/5000-00000001>AGI Tx >> agi_calleridname: Max <SIP/5000-00000001>AGI Tx >> agi_callingpres: 0 <SIP/5000-00000001>AGI Tx >> agi_callingani2: 0 <SIP/5000-00000001>AGI Tx >> agi_callington: 0 <SIP/5000-00000001>AGI Tx >> agi_callingtns: 0 <SIP/5000-00000001>AGI Tx >> agi_dnid: 62 <SIP/5000-00000001>AGI Tx >> agi_rdnis: unknown <SIP/5000-00000001>AGI Tx >> agi_context: phones <SIP/5000-00000001>AGI Tx >> agi_extension: 62 <SIP/5000-00000001>AGI Tx >> agi_priority: 2 <SIP/5000-00000001>AGI Tx >> agi_enhanced: 0.0 <SIP/5000-00000001>AGI Tx >> agi_accountcode: DM <SIP/5000-00000001>AGI Tx >> agi_threadid: 140606716917504 <SIP/5000-00000001>AGI Tx >> <SIP/5000-00000001>AGI Rx << STREAM FILE demo-congrats "#" 0 -- Playing 'demo-congrats' (escape_digits=#) (sample_offset 0) <SIP/5000-00000001>AGI Tx >> 200 result=35 endpos=100800 -- <SIP/5000-00000001>AGI Script index.php completed, returning 0 -- Executing [62@phones:3] Hangup("SIP/5000-00000001", "") in new stack == Spawn extension (phones, 62, 3) exited non-zero on 'SIP/5000-00000001' -- Executing [h@phones:1] NoOp("SIP/5000-00000001", "16--") in new stack

Its done now!!

it was a problem with agi version and php version.

I just prefixed an underscore before goto() function’s name in class agi and this solved the problem.

Thanks for your help.

Newest version of phpagi avoid that problem.

Its the latest version of the php agi. But thanks now!! it has been solved