PHP code example of freeswitch / php-client
1. Go to this page and download the library: Download freeswitch/php-client library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
freeswitch / php-client example snippets
`
class example implements \FreeSwitch\Event\EventHandleInterface {
/**
* @param array $event_recv 监听事件返回的包
*/
public function process(array $event_recv)
{
// todo
}
/**
* 外呼接口
*/
function outbound()
{
$caller = '****'; // 被叫
$callee = '****'; // 主叫
$fs = new \FreeSwitch\FreeSwitch(['host'=>'127.0.0.1','port'=>'12345','password'=>'******']);
$fs->startCall($caller, $callee); // 开始呼叫
// 退出事件监听示例(或者其他方式调用,不在同一协程下不会被阻塞,但是得注意您的上下文关系,避免造成变量污染或内存泄漏等问题)
Timer::after(1000,function ()use ($freeSwitch){
$freeSwitch->close();
});
$fs->eventListening($this); // 事件监听,并注入事件处理类(注意:监听事件是阻塞的)
}
}