laravel-rabbitmq/producer/app/Console/Commands/Socket.php

48 lines
969 B
PHP

<?php
namespace App\Console\Commands;
use ElephantIO\Client;
use ElephantIO\Engine\SocketIO\Version2X;
use ElephantIO\Engine\SocketIO\Version4X;
use Illuminate\Console\Command;
class Socket extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'socket';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$url = env('SOCKET_IO');
// if client option is omitted then it will use latest client available,
$client = new Client(new Version4X($url));
$client->connect();
// Sending a message to the server
$client->emit('message', ['Hello, server!']);
// Close the connection when done
$client->disconnect();
}
}