PHPAGI: Exec format error

隐身守侯 提交于 2019-12-12 09:53:10

问题


Encountering a problem when running 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


回答1:


The Exec Format Error is from /bin/bash, asterisk executes hello_world.php as a bash script.

shebang

If you add a correct shebang, the script get executed by the given PHP intepreter. 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:
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.

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

and call it in the Dialplan AGI("hello_world.sh").

Make sure the shellscript is executable chmod +x hello_world.sh.




回答2:


I added following line on top script to get it working for me

#!/usr/bin/php -q



回答3:


You issue is not asterisk issue,but general linux one.

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.




回答4:


Could you check your extensions.conf or extensions_custom.conf, if the extension and priority are not continuous also this error will occur.

please check the below example:

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


来源:https://stackoverflow.com/questions/15713359/phpagi-exec-format-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!