FreeSWITCH ESL添加PHP模块支持 freeswitch-esl-php
Song •
2797 次浏览 •
0个评论 •
2018年12月16日
此功能库基于freeswitch
的mod_event_socket
模块开发,支持所有版本PHP
;mod_event_socket
是一个基于TCP
的接口来控制FreeSWITCH
。默认值是绑定到127.0.0.1
端口8021
,默认密码是ClueCon
。
一、环境配置
你可以使用任何版本的php
进行连接,freeswitch
可以是远程服务器也可以是本地。
- php
- freeswitch
二、快速开始
使用前先clone
线上库,然后运行代码测试Demo
即可。
git clone
cd freeswith_php_esl
然后运行测试代码即可测试:
> php demo.php
FreeSWITCH Version 1.9.0+git~20180619T173242Z~25e9376b29~64bit (git 25e9376 2018-06-19 17:32:42Z 64bit)
三、API列表
1、connect(ip,port,password)
用于连接freeswitch
服务器,返回结果为true
或false
;使用方法如下:
<?php
require_once 'freeSwitchEsl.php';
$freeswitch = new Freeswitchesl();
$connect = $freeswitch->connect("127.0.0.1","8021","ClueCon");
if ($connect) {
echo "connect success";
}
如果登陆失败会输出错误信息,可以自己去掉注释。
2、api(api comment,args)
通过ESL
执行API
命令,此API
会返回数据执行结果,如果不想等待数据返回或者异步执行可以直接使用下方bgapi
:
$version = $freeswitch->api("version");
$status = $freeswitch->api("status");
$sofia = $freeswitch->api("sofia status");
更多freeswitch
的api
命令可以执行:
$sofia = $freeswitch->api("show api");
3、bgapi(api comment,args)
与api(api comment)
方法相同,非阻塞模式异步执行:
$originate = $freeswitch->bgapi("originate user/1000 &echo");
4、execute(comment,args,uuid)
与api(api comment)
方法相同,异步执行:
$originate = $freeswitch->bgapi("originate user/1000 &echo");
execute
5、executeAsync(comment,args,uuid)
与api(api comment)
方法相同,异步执行:
$originate = $freeswitch->bgapi("originate user/1000 &echo");
execute
6、events(sorts,args)
event
命令用于订阅来自FreeSWITCH
的事件。您可以在同一行上指定监听的所有的事件,它们应该用空格分隔;sorts
即返回数据类型,args
即监听的事件。
$status = $freeswitch->events("plain","ALL");
7、recvEvent()
与events(sorts,args)
配套使用,用于获取所有数据,返回服务器的原始数据。
$received_parameters = $freeswitch->recvEvent();
a、serialize(received_parameters,type)
serialize
即按住指定格式返回数据,建议与events
监听的类型一样,这样处理性能更加优秀;type
有plain、json
和xml
三种类型。
$serialize_info = $freeswitch->serialize($received_parameters,"xml");
b、getHeader(received_parameters,args)
可以获取返回的指定数据,如果不存在则返回空。
$Event_Name = $freeswitch->getHeader($received_parameters,"Event-Name");
使用例子:
<?php
require_once 'freeSwitchEsl.php';
$freeswitch = new Freeswitchesl();
$connect = $freeswitch->connect("127.0.0.1","8021","ClueCon");
if ($connect) {
$status = $freeswitch->events("json","ALL");
while (true) {
$received_parameters = $freeswitch->recvEvent();
if (!empty($received_parameters)) {
$info = $freeswitch->serialize($received_parameters,"json");
var_dump($info);
$Event_Name = $freeswitch->getHeader($received_parameters,"Event-Name");
echo $Event_Name;
}
}
}
7、disconnect()
断开php
与freeswitch
之间的socket
;建议每次使用后都需要断开。
用户评论
当前暂无评价,快来发表您的观点吧...
更多相关好文
当前暂无更多相关好文推荐...
-
微信公众号文章/菜单添加小程序时路径如何获取? 2021-12-22
-
如何轻松获取微信小程序路径path? 2021-12-22
-
cannot import name 'CUDA_HOME' from 'mmcv.utils' 2021-12-05
-
vgg的loss一轮达到ln(1/n)阈值,如何解决 2021-11-21
-
如何下载使用utils库 2021-10-27
热门文章
-
微信公众号文章/菜单添加小程序时路径如何获取? 2021-12-22
-
如何轻松获取微信小程序路径path? 2021-12-22
-
python/MySQL分页查询方法与性能优化 2021-06-23
-
mitmproxy & python 忽略所有的https/ssl请求 2021-04-19
-
如何使用邮件/邮箱推广微信公众号/小程序? 2021-01-28
栏目最新文章
公告提示
- pytorch中文文档
- pytorch官方文档
提交评论