1. Go to this page and download the library: Download joni-jones/yii2-wschat 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\commands;
use jones\wschat\components\Chat;
use jones\wschat\components\ChatManager;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
class ServerController extends \yii\console\Controller
{
public function actionRun()
{
$server = IoServer::factory(new HttpServer(new WsServer(new Chat(new ChatManager()))), 8080);
$server->run();
}
}
$manager = Yii::configure(new ChatManager(), [
'userClassName' => '\yii\db\ActiveRecord' //allow to get users from MySQL or PostgreSQL
]);
yii server/run
echo ChatWidget::widget();
echo ChatWidget::widget([
'auth' => true,
'user_id' => '' // setup id of current logged user
]);