项目作者: Izumi-kun

项目描述 :
Implements long polling connection
高级语言: PHP
项目地址: git://github.com/Izumi-kun/yii2-longpoll.git
创建时间: 2017-01-26T21:56:44Z
项目社区:https://github.com/Izumi-kun/yii2-longpoll

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Yii2 longpoll

Implements long polling AJAX mechanism.

Latest Stable Version
Total Downloads
Build Status
Scrutinizer Code Quality
Code Coverage

Installation

The preferred way to install this extension is through composer.

Either run

  1. php composer.phar require --prefer-dist izumi-kun/yii2-longpoll

or add

  1. "izumi-kun/yii2-longpoll": "~1.0.0"

to the require section of your composer.json.

Basic Usage

Controller

  1. class SiteController extends Controller
  2. {
  3. public function actions()
  4. {
  5. return [
  6. 'polling' => [
  7. 'class' => LongPollAction::class,
  8. 'events' => ['eventId'],
  9. 'callback' => [$this, 'longPollCallback'],
  10. ],
  11. ];
  12. }
  13. public function longPollCallback(Server $server)
  14. {
  15. $server->responseData = 'any data';
  16. }
  17. }

View

  1. LongPoll::widget([
  2. 'url' => ['site/polling'],
  3. 'events' => ['eventId'],
  4. 'callback' => 'console.log',
  5. ]);

Model

  1. \izumi\longpoll\Event::triggerByKey('eventId');

Example

https://github.com/Izumi-kun/yii2-longpoll-example

License

BSD-3-Clause