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

发布于 2024-12-20 11:04:49 字数 1106 浏览 3 评论 0原文

我的想法是我想在 Asterisk 的拨号计划中执行 PHP 脚本。它的工作方式就像一个守护进程/进程,从星号获取值并用它们做一些事情。但是,当我执行 system(php script.php) 命令时,Asterisk 会停止并且不会进入下一个拨号计划步骤。我相信,原因是 script.php 内部有“while(1) {...}”循环,而 Asterisk 等待其结束...

你能帮助我并给我看一些吗解决方案如何运行外部“php-loop”脚本并一次执行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

#!/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;
  */
  }
?>

因此,正如您所看到的,这个想法很简单:使用“循环”启动 php 脚本,同时从底部步骤执行其他操作在[内部]背景下。 怎么处理呢?因为 Asterisk 等待 script.php 执行结束,然后他进入下一步。

谢谢你!

My idea is that I want to execute a PHP script in Asterisk's dial-plan. 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. The reason is that, I believe, the script.php has "while(1) {...}" loop inside and Asterisk waits for its end...

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?

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

#!/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.
How to handle it? Because Asterisk waits for the end of the script.php execution and then he goes to the next step.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤檠 2024-12-27 11:04:49

Asterisk 中的 Agi 被阻挡。拨号计划的执行将等到 agi 死亡后再继续。如果你希望你的 agi 运行而不管 Dialplan,请查看 Fastagi,它是一个你通过套接字连接的 agi 守护进程(它的寿命很长,与 Asterisk 无关且独立)。只是不要忘记在调用 agi 之前在拨号方案中设置 ${AGISIGHUP}=no 。

有关 AGI 的示例,请参阅此处,并查看 < a href="http://www.freepbx.org" rel="nofollow">FreePBX 的 许多模块。

Agi's in Asterisk are blocking. Dialplan execution will wait until the agi dies before continuing. 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). Just dont forget to set ${AGISIGHUP}=no in your dialplan BEFORE calling the agi.

For examples of AGI's see here and check out some the scripts included in FreePBX's many modules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文