How to execute php script from dialplan

Hi, How does one exceute a normal php script from the dialplan, not an agi one

Is it just Dial(process.php)

THanks

I would suspect that you would use SYSTEM.

I’ve done this using SYSTEM as mazzic suggested.

use System(with full php file name)


www.itdiscussiongroup.com

how can i use “System” cmd and pass a variable to the php script?

It is simple, pass it after the file name like

system(/myscripts/myfile.php $arg1 $arg2)

it should work

Hi,

well, i’m trying the same but no luck for now

DIALPLAN:

exten=> 111,1,Answer()
exten=> 111,2,Wait(1)
exten=> 111,3,Set(foo=${CALLERID(num)})
exten=> 111,4,System(/opt/phptest/test.php ${foo})
exten=> 111,5,Hangup()

PHP:

<?php
$foo = $_GET['foo'];
$myFile = "/opt/phptest/test".$foo.".txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $foo);
fclose($fh);
?>

CLI:

    -- Executing [111@default:1] Answer("SIP/202-b77dfee0", "") in new stack
    -- Executing [111@default:2] Wait("SIP/202-b77dfee0", "1") in new stack
    -- Executing [111@default:3] Set("SIP/202-b77dfee0", "foo=202") in new stack
    -- Executing [111@default:4] System("SIP/202-b77dfee0", "/opt/phptest/test.php 202") in new stack

As a result nothing happens?, where am i doing wrong.
asterisk 1.6.0.10
trixbox 2.8.0.4

Why don’t you try with PHPAGI, and use the application AGI instead SYSTEM.

Hi,
currently i’m switched to agi as folows:

This code below works, it writes txt file with Bobby Bopper.
but if i add argumet to dialplan AGI(pozovi.php ${CallerID}) and, add variable to agi script, $CallerID = $_GET[‘CallerID’]; it wont execute!.

DIALPLAN:

exten=> 111,1,Wait(1)
exten=> 111,2,Set(CallerID=${CALLERID(num)})
exten=> 111,3,AGI(pozovi.php)
exten=> 111,4,Hangup()

PHP:

#!/usr/bin/php -q
<?php
{
GLOBAL	$stdin, $stdout, $stdlog, $result, $parm_debug_on, $parm_test_mode;
    
ob_implicit_flush(false); 
set_time_limit(30);
error_reporting(0);

$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');

# Retrieve all AGI variables from Asterisk
	while ( !feof($stdin) ) 
	{
		$temp = fgets( $stdin );
		
		if ($parm_debug_on)
			fputs( $stdlog, $temp );
		
		// Strip off any new-line characters
		$temp = str_replace( "\n", "", $temp );
		
		$s = explode( ":", $temp );
		$agivar[$s[0]] = trim( $s[1] );
		if ( ( $temp == "") || ($temp == "\n") )
		{
			break;
		}
	}
# Print all AGI variables for debugging purposes
    foreach($agi as $key=>$value)
    {
        fwrite(STDERR,"-- $key = $value\n");
        fflush(STDERR);
    }

$myFile = "/opt/phptest/testCallerID.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData);
fclose($fh);

}
?>

Now i’m sure that no variable(CallerID) get passed to php agi from asterisk.

exten=> 111,1,Wait(1)
exten=> 111,2,Set(CallerID=${CALLERID(num)})
exten=> 111,3,AGI(pozovi.php, ${CallerID})
exten=> 111,4,Hangup()
#!/usr/bin/php -q
<?php
{
GLOBAL	$stdin, $stdout, $stdlog, $result, $parm_debug_on, $parm_test_mode;
    
ob_implicit_flush(false); 
set_time_limit(30);
error_reporting(0);

$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');

# Retrieve all AGI variables from Asterisk
	while ( !feof($stdin) ) 
	{
		$temp = fgets( $stdin );
		
		if ($parm_debug_on)
			fputs( $stdlog, $temp );
		
		// Strip off any new-line characters
		$temp = str_replace( "\n", "", $temp );
		
		$s = explode( ":", $temp );
		$agivar[$s[0]] = trim( $s[1] );
		if ( ( $temp == "") || ($temp == "\n") )
		{
			break;
		}
	}
# Print all AGI variables for debugging purposes
    foreach($agi as $key=>$value)
    {
        fwrite(STDERR,"-- $key = $value\n");
        fflush(STDERR);
    }

$CallerID = $_GET['CallerID'];
$myFile = "/opt/phptest/testCallerID.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Betty\n";
fwrite($fh, $CallerID);
fclose($fh);

}
?>

O.k. solved by digging though out to China!, had to add line
extract($agivars);
$CallerID=$agivar[agi_callerid];
fwrite(STDOUT, “$CallerID”);