emmmm...之前那个是5.1的5.4好像有点不一样
首先composer workerman
composer require workerman/workerman
1.服务端
php artisan make:command workerman
然后>/app/Console/Commands下面就会创建一个文件workerman.php
我们改一改signature description 还有handle方法...↓
记得引入workerman
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App;
use Workerman\Worker;
class WorkermanServer extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'workerman:command {action} {-d}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Workerman Server';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$ws = new Worker("websocket://0.0.0.0:9011");
$ws->count = 4;
$ws->onConnect = function($connection)
{
echo "new connection\n";
};
$ws->onMessage = function($connection, $data)
{
echo $data."\n";
$connection->send('hello1');
};
$ws->onClose = function($connection)
{
echo "Connection closed\n";
};
// Run worker
Worker::runAll();
}
}
然后...
就Ok了...
2.测试一下
打开浏览器输入ip:端口
这个不管他↓
呼出控制台...
就Ok啦
出问题了复制报错信息百度,能解决90%以上的问题.