Long Polling

Walrus let you setup a long polling script in a very simple way, long polling work best on API route, because API route a way more lightweight and handle for you HTPP code response and JSON output

The first step is to subscribe to the Walrus long polling, for this create a controller with an empty action and add the following line:

    public function run()
    {
        return self::setPolling(array('table1', 'table2'), array(&$this, 'callbackFunction'));
    }

This will setup the long polling, the first argument is an array of the table you want to subscribed, and the second one an array with two row, the first is the current class &$this and the second an action name
Now wen need to create this callback function, the callback function have two tings to do, the first one is to get the last inserted rows for each of the tables you want (we assume that you have a table1 and table2 model with working get actions), you can use self::$last_ids['yourtable'] to know the last id getted by the user:

    public function run()
    {
        return self::setPolling(array('table1', 'table2'), array(&$this, 'callbackFunction'));
    }

    public function callbackFunction()
    {
        $table1 = $this->model('table1')->getLasts(self::$last_ids['table1']);
        $table2 = $this->model('table2')->getLasts(self::$last_ids['table2']);
    }

The second and last thing to do is to verify if we have received some data, and if so, return the data. Walrus long polling also need from you the last received id, this is really simple to do (this can be simplified but it's more explicit on this way):

    public function run()
    {
        return self::setPolling(array('table1', 'table2'), array(&$this, 'callbackFunction'));
    }

    public function callbackFunction()
    {
        $table1 = $this->model('table1')->getLasts(self::$last_ids['table1']);
        $table2 = $this->model('table2')->getLasts(self::$last_ids['table2']);

        if (!empty($table1)) {
            $response['table1'] = $table1;
            self::$last_ids['table1'] = end($table1)['id'];
        }

        if (!empty($table2)) {
            $response['table2'] = $table1;
            self::$last_ids['table2'] = end($table2)['id'];
        }

        if (isset($response)) {
            return $response;
        }
    }

That's all ! your long polling is fully setup on your backend. Now you need to request it with Walrus.js, take a look to Walrus FrontEnd long polling