○
配置环境
当前使用的是centos7,配置环境是lnmp,php用php72。thinkphp用tp5最新版,selinux、linux的防火墙直接关闭。上传服务器用的是git
需要注意的是:
1:php安装要把posix跟pcntl扩展装上,不然后期不能用workman
2:thinkphp5的nginx要配置支持pathinfo模式
3:thinkphp5下载下来是用git上传的话是忽略thinkphp文件夹的。需要特别注意在服务器端直接上传这个文件或者在.gitignore文件中把它删掉
nginx.conf配置支持thinkphp5的路由配置
在server内添加:
location ~.php {
root /wwwroot/html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi权限,支持 ?s=/module/controller/action 的url访问模式
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#下面两句才能支持 index.php/index/index/index的pathinfo模式
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
安装
安装composer
1:配置环境
#export PATH=$PATH:/usr/local/php720/bin/
#curl -sS https://getcomposer.org/installer | php
# mv composer.phar /usr/local/bin/composer
#composer config -g repo.packagist composer https://packagist.phpcomposer.com
2:安装thinkphp
复制即可
3:安装workerman
测试是否满足workerman安装条件
安装
#composer require topthink/think-worker
4:配置、测试 workerman
(参考:https://www.kancloud.cn/manual/thinkphp5/235128)
项目根目录
/server.php
define('APP_PATH', __DIR__ . '/application/');
define('BIND_MODULE','push/worker');
require __DIR__ . '/thinkphp/start.php';
/application/push/controller/Worker.php
namespace app\push\controller;
use think\worker\Server;
class Worker extends Server{
protected $socket = 'websocket://192.168.1.223:2346';
//收到信息
public function onMessage($connection, $data){
$connection->send('我收到你的信息了');
}
// 当连接建立时触发的回调函数
public function onConnect($connection){
}
//当连接断开时触发的回调函数
public function onClose($connection) {
}
//当客户端的连接上发生错误时触发
public function onError($connection, $code, $msg){
echo "error $code $msg\n";
}
//每个进程启动
public function onWorkerStart($worker) {
}
public function index(){
}
}
后续操作请等候
龙有逆鳞,总是被藏在龙最敏感的位置。而你在我心里的心里,是逆鳞中的逆鳞。
谢谢你们的观看
我是沈恒
春暖花开,天心月圆。
领取专属 10元无门槛券
私享最新 技术干货