forked from matyhtf/webim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebim_server.php
33 lines (27 loc) · 914 Bytes
/
webim_server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
define('DEBUG', 'on');
define("WEBPATH", realpath(__DIR__ . '/../'));
require __DIR__.'/vendor/autoload.php';
Swoole\Loader::vendor_init();
Swoole\Loader::setRootNS('WebIM', __DIR__.'/src/');
$config = require __DIR__.'/config.php';
//将配置写入config.js
$config_js = <<<HTML
var webim = {
'server' : '{$config['server']['url']}'
}
HTML;
file_put_contents(__DIR__ . '/client/config.js', $config_js);
$webim = new WebIM\Server();
$webim->loadSetting(__DIR__."/swoole.ini"); //加载配置文件
$webim->setLogger(new Swoole\Log\FileLog($config['webim']['log_file'])); //Logger
/**
* 使用文件或redis存储聊天信息
*/
$webim->setStore(new WebIM\Store\File($config['webim']['data_dir']));
/**
* webim必须使用swoole扩展
*/
$server = new Swoole\Network\Server($config['server']['host'], $config['server']['port']);
$server->setProtocol($webim);
$server->run($config['swoole']);