thevoipman
thevoipman

Reputation: 1833

asterisk agi loop not working

I am trying to have my php script loop 10 times when a call is made, but for some reason it only executes once and then it hangup/dies/exit. Any kind of insight I can get on this is greatly appreciated.

 for ($i=1; $i<=10; $i++)
ob_implicit_flush(true);
require_once('phpagi.php');

$agi = new AGI();
$agi->answer();


  list ($id,$number,$callerid) = mysql_fetch_row(mysql_query("select `called`,`tollfree`,`callerid` from `avotfmaster`.`cdr` where `pbx`='0' order by `mins` desc, rand() limit 1",$xb));

if($id) {

$agi->set_callerid("$callerid");
$agi->exec('DIAL',"SIP/31282200*[email protected],40,L(60000)");


$gwopt_dtmf = $agi->get_data('confirm', 3000, 1);

if($gwopt_dtmf['result']==1)
        {
mysql_query("UPDATE `avotfmaster`.`cdr` SET `pbx`='1' WHERE `number`='$number'",$xb);


        } else {
        mysql_query("UPDATE `avotfmaster`.`cdr` SET `pbx`='2' WHERE `number`='$number'",$xb);
$agi->verbose("I will go ahead and mark this number already scanned and tested");

}

}
}

Upvotes: 0

Views: 1069

Answers (2)

Niek Klein Kromhof
Niek Klein Kromhof

Reputation: 164

It is not a good idea to call things like Dial, basically anything that ties your script up for an undetermined (or possibly long) amount of time, from a PHPAGI script.

System resources are not released until after the script ends. For this reason there is a maximum script execution duration command in PHP, I bet your script runs longer than the default allowed amount of time (on most calls) and the script gets terminated.

See this answer for clues: PHP set_time_limit() does not work, safemode is off

Upvotes: 1

arheops
arheops

Reputation: 15259

Please read documentation for Dial.

If you need control AFTER that function, you need add "g" key to options.

Upvotes: 0

Related Questions