Asterisk *发起一个播放php脚本,但得到fwrite()断管

时间:2016-06-17 07:10:04

标签: php asterisk

您好我正在开发Asterisk框架工作,我正在编写一个php脚本,我可以在meetme会议中播放语音消息。

不知何故,我的php脚本返回此错误:

ERROR[27555]: utils.c:1390 ast_careful_fwrite: fwrite() returned error: Broken pipe

这是我的php脚本:

<?PHP


set_time_limit(0);

$filename = $_GET['click'];

$socket = fsockopen("127.0.0.1","5038", $errno, $errstr, 10);

 if (!$socket) { echo "$errstr ($errno)\n";
echo fgets($socket).'<br>';}

else {
 fputs($socket, "Action: Login\r\n");
 fputs($socket, "UserName: myasterisk\r\n");
 fputs($socket, "Secret: *****\r\n\r\n");
 fputs($socket, "Action: Command\r\n");
// fputs($socket, "Command: sip show peers\r\n\r\n");
 fputs($socket, "Command: meetme(2500,p)\r\n\r\n");
 fputs($socket, "Command: Playback($filename)\r\n\r\n");
 fputs($socket, "Command: Hangup()\r\n\r\n");
 fputs($socket, "Action: Logoff\r\n\r\n");

 echo fgets($socket).'<br>';

 fclose($socket);
 }
error_reporting(E_ALL);

?>

请查看我犯错误的地方。

如何将此脚本运行到我的拨号计划中,优先进入meetme会议,然后通过执行此脚本播放音频?

请帮助我,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

请确保注销正常工作,看起来您在注销前正在关闭连接。

更多详情:

http://forums.asterisk.org/viewtopic.php?f=1&t=75713

更新

可能问题是你没有从AMI套接字读取所有内容。请尝试以下代码:

<?php

set_time_limit(0);

$filename = $_GET['click'];

$socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout);
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: myasterisk\r\n");
fputs($socket, "Secret: *****\r\n\r\n");
fputs($socket, "Command: meetme(2500,p)\r\n\r\n");
fputs($socket, "Command: Playback($filename)\r\n\r\n");
fputs($socket, "Command: Hangup()\r\n\r\n");
fputs($socket, "Action: Logoff\r\n\r\n");
while (!feof($socket)) {
  $wrets .= fread($socket, 8192);
}
fclose($socket);
echo <<<ASTERISKMANAGEREND
ASTERISK MANAGER OUTPUT:
$wrets
ASTERISKMANAGEREND;
?>