Pusher with FuelPHP

Pusher debug page
Pusher API Debug Page

Using Pusher with native PHP is relatively easy. But using it with a PHP Framework can be a little bit confusing, since it needs some additional work. Up to this date, there’s no Pusher PHP Library which is designed to work directly with FuelPHP. It just takes minutes to set up, though.

Setting Up Pusher

  1. Sign up for Pusher, if you haven’t got any account.
  2. Download the native PHP Pusher Library.
  3. Create a new directory “pusher” in your fuelPHP’s classes directory.
  4. Extract the file Pusher.php from the PHP Pusher Library arcive /lib to your pusher directory.
  5. Create a new file in your pusher directory: pusherinstance.php.
  6. Open the Pusher.php file. Cut the class PusherInstance to the file pusherinstance.php
  7. Close and rename the file Pusher.php into pusher.php (Note: it’s because UNIX system is case-sensitive, and fuelPHP assumes that your classes’ filename are all lowercased)
  8. Open the pusherinstance.php file. Enter your app credentials at the given attribute. See the Pusher API Access.

You’re done setting up Pusher. Now it’s for the real thing: test it out. You can use the existing example to quickly test your app.

  1. Go to the API Access page and take the Pastable HTML code, place it in your view.
  2. Go to Pusher PHP page. Use those examples at your controller, preferably different controller from the one controlling your view with JS from number 1.
  3. First, run the view with the JS (of course I mean, run it through a controller). Wait till it’s connected. You can see the console log in any “Inspect Element” menu of the browser.
  4. If it’s connected, then open a new browser tab, run your controller containing the example from the Pusher PHP. It should trigger the JS alert at your view with JS page.
  5. If the previous two steps is successful, congratulations, you are ready to use Pusher! See Pusher API Debug Page to monitor the connections.

Note: Just one mistake there at the Pusher PHP Presence example section: it’s not Pusher.auth_url. Instead, it should be Pusher.channel_auth_endpoint.

Good Luck!

Leave a Reply

Your email address will not be published. Required fields are marked *