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();
}
}
然后...
jianshu1.png
就Ok了...
2.測試一下
打開瀏覽器輸入ip:端口
jianshu4.png
這個不管他↓
jianshu3.png
呼出控制臺...
jianshu2.png
就Ok啦
出問題了復制報錯信息百度,能解決90%以上的問題.