在Linux下启动两个时报错
百度搜了一下加入$pidFile
Worker::$pidFile = app()->getRootPath().'MyCrontab.pid';
也还是不行
<?php
namespace app\YourApp\liunx;
use think\admin\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use think\console\input\Option;
use Workerman\Lib\Timer;
use Workerman\Connection\AsyncTcpConnection;
use Workerman\Worker;
use think\facade\Cache;
/**
* Worker 命令行类
*/
class Ceshi extends Command
{
public function configure()
{
$this->setName('Ceshi')
->addArgument('action', Argument::OPTIONAL, "start|stop|restart|reload|status|connections|OK", 'start')
->addOption('mode', 'm', Option::VALUE_OPTIONAL, 'Run the workerman server in daemon mode.')
->setDescription('the workerman command');
}
public function execute(Input $input, Output $output)
{
$action= $input->getArgument('action');
$mode = $input->getOption('mode');
Worker::$pidFile = app()->getRootPath().'MyCrontab.pid';
// 重新构造命令行参数,以便兼容workerman的命令
global $argv;
$argv = [];
array_unshift($argv, 'think', $action);
if ($mode == 'd') {
$argv[] = '-d';
} else if ($mode == 'g') {
$argv[] = '-g';
}
if ('OK' == $action) {
return "";
}
if ('start' == $action) {
$this->start(1, 0);
}
}
/**
* 启动
* @access public
* @return void
*/
public function start($bot1,$bot)
{
$worker = new Worker();
$worker->onWorkerStart = function()use($bot1,$bot)
{
$conC_url="ws://xxx";
$con_url="ws://xxx";
//配置
$conC = new AsyncTcpConnection($conC_url);$conC->transport = 'ssl';
// // 心跳定时器
Timer::add(20, function() use ($conC){$conC->send("ping");});
// 远程websocket服务器发来消息时
$conC->onMessage = function($connection, $data){
//实盘
$this->output->writeln(date('Y-m-d H:i:s',time()). "消息 ".$data." ");
};
// 连接上发生错误时,一般是连接远程websocket服务器失败错误
$conC->onError = function($connection, $code, $msg){};
// 当连接远程websocket服务器的连接断开时// 如果连接断开20秒后自动重连
$conC->onClose = function($connection){$this->output->writeln(date('Y-m-d H:i:s',time())." 重连"); $connection->reconnect(5);};
$conC->connect();
};
Worker::runAll();
}
}
Workerman[think] start in DEBUG mode
Workerman[think] already running
think Startws1 start 正常
think Startws2 start 不正常
两个pidfile的名称不能一样
可以了谢谢
启动文件要分开两个.一个写 startws1.pid. 一个写startws2.pid.
可以了谢谢