PHP code example of izumi-kun / yii2-longpoll

1. Go to this page and download the library: Download izumi-kun/yii2-longpoll 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/ */

    

izumi-kun / yii2-longpoll example snippets


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');