Downloads

Google Ad

CakePHP Who's Online Plugin

Date: Wed, Dec 2nd 2009, 18:41 Author: nick Views: 12728 Comments share

CakePHP Online Plugin

Info:
Watch:
Get it:
  • Download Now
  • git clone git://github.com/webtechnick/CakePHP-Online-Plugin
Wouldn't it be handy to see how many people are on your CakePHP app at any given time? Wouldn't it be nice to actually see where they currently are in your app? With this simple CakePHP plugin -- now you can

Simple Concept...

The idea is simple; anytime someone visits your app a small database entry is created logging what their IP is and what they're currently looking at. As they browse around your app their online status updates to what they're currently looking at. The log is kept clean every 10 minutes that same someone hasn't browsed your app.

The result is at anytime you'll be able to see an accurate list of online, active, users as well as where they currently are on your site.

Install

Installing is straight forward, just like any other plugin:
1) Copy the /online into your /app/plugins/online
2a) Run the online.sql into your database
2b) Run
  1. cake schema run create -path plugins/online/config/sql -name online
Note: If you choose the 'cake schema' route, I highly suggest you convert your database engine to MEMORY as it will be faster to access/write than the default engine CakePHP gives all tables. Note 2: If you choose 'cake schema' route, I suggest you change the 'ip' column to 'unsigned'
3) You'll need to add a bit of code to your app_controller.php

//app_controller.php
  1. var $uses = array('Online.Online');
  2.  
  3. function beforeRender(){
  4.   $this->Online->update($this->here);
  5. }

Once you have the database in place and those few lines of code in your app_controller.php you'll now be tracking your site's users -- you spy you.

How do I see who's online?

Funny you should ask, I've provided a few ways for you to see who's online.

1) You can use the built in OnlineHelper::all() which will return you an associative array of all the online users cakePHP style.
  1. //Some Controller
  2. var $helpers = array('Online.Online');
  3.  
  4. //Some view
  5. echo debug($online->all());

2) You can use the requestAction() which will again return you an associative array of all the online users cakePHP style.
  1. //Some view
  2. echo debug($this->requestAction('/online/onlines'));

3) You can use the built in Element (You will need to style this heavily to fit your site)
  1. echo $this->element('online', array('plugin' => 'online'));

Use whichever way you prefer. =)

Enjoy!

That's it, enjoy seeing who's online and what they're currently looking at.

As always, if you like the plugin, find a bug, or have a feature request -- post a comment.

If you use the plugin and want to help support it, please consider a small donation or just click an Ad a few times. ;)

Hope you find it useful,
Nick