AGI with script PHP

I’m trying to write my first script AGI with PHP.

My script, test1.agi in /var/lib/asterisk/agi-bin is:

#!/usr/bin/php -q

<?php set_time_limit(60); ob_implicit_flush(false); error_reporting(0); $stdlog = fopen("/var/log/asterisk/my_agi.log", "w"); fputs($stdlog, "ok!!!\n"); fclose($stdlog); return(100); ?>

From shell, using /usr/bin/php test1.agi, the script works fine. It create the file and write in the string “ok!!!”.

I create the following lines in extensions.conf:

exten => 711,1,Answer()
exten => 711,2,AGI(test1.agi)

When i call 711, in Asterisk log i see:

Executing Answer(“SIP/408-ad5b”, “”) in new stack
Executing AGI(“SIP/408-ad5b”, “test1.agi”) in new stack
Launched AGI Script /var/lib/asterisk/agi-bin/test1.agi
AGI Script test1.agi completed, returning 0

Therefore the script do not create the file my_agi.log.

I enabled the PHP log and it is working fine. If i run a wrong script i see the error in the log. If i run same script from Asterisk (calling 711) no error appear in PHP log.

Can you help me?

Thank’s.
Vittorio.

You need to place the script into asterisk agi-bin directory.
( {Asterisk Dir}/var/lib/agi-bin )

In my asterisk.conf

astagidir => /var/lib/asterisk/agi-bin

My test1.agi is in this directory.

Is incorrect?

Thank’s.

No, you make a place scripts anywhere, just type the path:
exten => 711,2,AGI(/xxx/xxx/xxx/test1.agi)
check the permission

I updated extensions.conf with:

exten => 711,2,AGI(/var/lib/asterisk/agi-bin/test1.agi)

with ps -aux i see /usr/sbin/asterisk is running as root

owner of /var/log/asterisk is root with rwxr-xr-x rights

but with no results.

Other ideas?