简体   繁体   English

PHPAGI:Exec格式错误

[英]PHPAGI: Exec format error

Encountering a problem when running phpagi: 运行phpagi时遇到问题:

-- Executing [123@DLPN_C:1] AGI("SIP/1000-00000001", "hello_world.php") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/hello_world.php
hello_world.php: Failed to execute '/var/lib/asterisk/agi-bin/hello_world.php': Exec format error
-- Auto fallthrough, channel 'SIP/1000-00000001' status is 'UNKNOWN' Scheduling destruction of SIP dialog '343930130' in 32000 ms (Method: INVITE)

From command line: 从命令行:

root@asterisk-test:/var/lib/asterisk/agi-bin# php5 -q hello_world.php 
#!/usr/bin/php5 -q

Additional info: 附加信息:

-rwxr-xr-x  1 root     root       757 Mar 29 19:32 hello_world.php
drwxrwxr-x  4 root     root      4096 Mar 29 19:44 phpagi
-rwxr-xr-x  1 root     root     25079 Sep 30  2010 phpagi-asmanager.php
-rwxr-xr-x  1 root     root      2322 Sep 30  2010 phpagi-fastagi.php
-rwxr-xr-x  1 root     root     67615 Sep 30  2010 phpagi.php

Source of hello world: http://www.eder.us/projects/phpagi/phpagi/api-docs/__examplesource/exsource_home_html_projects_phpagi_phpagi_examples_dtmf.php_acb7257145e4a5249182c8373cd8e848.html 你好世界的来源: http//www.eder.us/projects/phpagi/phpagi/api-docs/__examplesource/exsource_home_html_projects_phpagi_phpagi_examples_dtmf.php_acb7257145e4a5249182c8373cd8e848.html

The Exec Format Error is from /bin/bash , asterisk executes hello_world.php as a bash script. Exec Format Error来自/bin/bash ,asterisk将hello_world.php作为bash脚本执行。

shebang 家当

If you add a correct shebang , the script get executed by the given PHP intepreter. 如果添加正确的shebang ,脚本将由给定的PHP解释器执行。 The first Line tells the System which program should run the script. 第一行告诉系统哪个程序应该运行脚本。

#!/usr/bin/env php

To test your shebang, execute the script itself, not by PHP: 要测试你的shebang,请执行脚本本身,而不是PHP:
root@asterisk-test:/var/lib/asterisk/agi-bin# ./hello_world.php

Make sure it is executable with: 确保它是可执行的:
root@asterisk-test:/var/lib/asterisk/agi-bin# chmod +x hello_world.php

alternative wrapper 替代包装

Create a bash script that executes the PHP script. 创建一个执行PHP脚本的bash脚本。

example hello_world.sh: 示例hello_world.sh:
/usr/bin/php hello_world.php

and call it in the Dialplan AGI("hello_world.sh") . 并在Dialplan AGI("hello_world.sh")调用它。

Make sure the shellscript is executable chmod +x hello_world.sh . 确保shellscript是可执行的chmod +x hello_world.sh

我在顶级脚本上添加了以下行以使其适合我

#!/usr/bin/php -q

You issue is not asterisk issue,but general linux one. 你问的不是星号问题,而是一般的linux问题。

Please try from your command line following: 请尝试从以下命令行:

su asterisk -c "/var/lib/asterisk/agi-bin/hello_world.php"

Most likly reasons: php path is incorrect or selinux enabled and not configured. 最可能的原因:php路径不正确或启用了selinux且未配置。

Could you check your extensions.conf or extensions_custom.conf , if the extension and priority are not continuous also this error will occur. 你可以检查你的extensions.confextensions_custom.conf ,如果扩展和优先级不连续,也会发生这个错误。

please check the below example: 请查看以下示例:

[context]
exten => 1,1,Answer()
exten => 1,2,AGI(your-agi-script)
exten => 1,3,Hangup()

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

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