简体   繁体   English

PHP脚本中的循环由星号执行

[英]loop in php script executes by asterisk

My idea is that I want to execute a PHP script in Asterisk's dial-plan. 我的想法是我想在Asterisk的拨号计划中执行一个PHP脚本。 It works like a deamon/process that gets values from the Asterisk and does something with them. 它就像一个守护进程/进程,从星号获取值并对其进行处理。 But when I do the system(php script.php) command Asterisk stops and does not go to the next dial-plan step. 但是,当我执行system(php script.php)命令时,星号会停止并且不会进入下一个拨号计划步骤。 The reason is that, I believe, the script.php has "while(1) {...}" loop inside and Asterisk waits for its end... 我相信,原因是我的script.php内部有“ while(1){...}”循环,而Asterisk等待其结束...

Could you help me and show me some solution how to run external "php-loop" script and go through extensions.conf steps at one time? 您能帮我看看一些解决方案,如何运行外部“ php-loop”脚本并一次执行extensions.conf步骤吗?

extensions.conf extensions.conf

[internal]
exten => 100,1,Set(CallerId=${CALLERID(num)}) ;get number
exten => 100,n,System(php script.php ${CallerId}) ;execute php script with argv[1]
;now the script.php should run at the background and below part
;should be execute like in ordinary context
exten => 100,n,Dial(SIP/100)
exten => 100,n,Hangup()

script.php script.php

#!/usr/bin/php
<?php
  $num = argv[1]; //the value from [internal] in the extensions.conf
  while(1) { //start the loop
  /*
   * do something in the infinite loop and END it IF something happen
   * e.g. $someVal == 9999;
  */
  }
?>

So, as you can see the idea is simple: start the php script with the 'loop' and in meantime do something else from the bottom steps in the [internal] context. 因此,正如您所看到的,这个想法很简单:使用“循环”启动php脚本,同时在[内部]上下文的最底层执行其他操作。 How to handle it? 怎么处理呢? Because Asterisk waits for the end of the script.php execution and then he goes to the next step. 因为Asterisk等待script.php执行的结束,然后转到下一步。

Thank you! 谢谢!

Agi's in Asterisk are blocking. 星号中的Agi正在阻止。 Dialplan execution will wait until the agi dies before continuing. Dialplan执行将一直等到agi消失后再继续。 If you want your agi to run regardless of the Dialplan, look in to Fastagi, which is an agi deamon that you connect to via a socket (its long living, irrespective and independent of Asterisk). 如果要使agi不受Dialplan的影响而运行,请查看Fastagi,它是一种agi守护程序,可通过套接字(其寿命长,与Asterisk无关,并且独立于此)连接。 Just dont forget to set ${AGISIGHUP}=no in your dialplan BEFORE calling the agi. 只是不要忘记在调用agi之前在拨号计划中设置$ {AGISIGHUP} = no。

For examples of AGI's see here and check out some the scripts included in FreePBX's many modules. 有关AGI的示例,请参见此处,并查看FreePBX的许多模块中包含的一些脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM