1. Go to this page and download the library: Download aoeng/laravel-workerman library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Listeners;
use Aoeng\Laravel\Workerman\Events\WorkermanOnMessage;
use Aoeng\Laravel\Workerman\Facades\Gateway;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class HandleSocketMessage
{
/**
* Handle the event.
*
* @param WorkermanOnMessage $event
* @return void
*/
public function handle(WorkermanOnMessage $event)
{
info('测试', [$event->message]);
Gateway::sendToCurrentClient('你说的对');
}
}
// Providers/EventServiceProvider.php
public function shouldDiscoverEvents()
{
return true;
}