Implements long polling AJAX mechanism.
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist izumi-kun/yii2-longpoll
or add
"izumi-kun/yii2-longpoll": "~1.0.0"
to the require section of your composer.json.
class SiteController extends Controller
{
public function actions()
{
return [
'polling' => [
'class' => LongPollAction::class,
'events' => ['eventId'],
'callback' => [$this, 'longPollCallback'],
],
];
}
public function longPollCallback(Server $server)
{
$server->responseData = 'any data';
}
}
LongPoll::widget([
'url' => ['site/polling'],
'events' => ['eventId'],
'callback' => 'console.log',
]);
\izumi\longpoll\Event::triggerByKey('eventId');
https://github.com/Izumi-kun/yii2-longpoll-example
BSD-3-Clause