PHP code example of aoeng / laravel-workerman

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/ */

    

aoeng / laravel-workerman example snippets


Aoeng\Laravel\Workerman\Events\WorkermanOnWorkerStart::class
Aoeng\Laravel\Workerman\Events\WorkermanOnConnect::class
Aoeng\Laravel\Workerman\Events\WorkermanOnWebSocketConnect::class
Aoeng\Laravel\Workerman\Events\WorkermanOnMessage::class
Aoeng\Laravel\Workerman\Events\WorkermanOnClose::class
Aoeng\Laravel\Workerman\Events\WorkermanOnWorkerStop::class
 
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;
} 

 
//例如 
 Aoeng\Laravel\Workerman\Facades\Gateway::isUidOnline($uid);
bash
php artisan workerman start|stop|restart|reload|status [--d]