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
- Sign up for Pusher, if you haven’t got any account.
- Download the native PHP Pusher Library.
- Create a new directory “pusher” in your fuelPHP’s classes directory.
- Extract the file Pusher.php from the PHP Pusher Library arcive
/libto your pusher directory.
- Create a new file in your pusher directory:
- Open the
Pusher.phpfile. Cut the class
PusherInstanceto the file
- Close and rename the file
pusher.php(Note: it’s because UNIX system is case-sensitive, and fuelPHP assumes that your classes’ filename are all lowercased)
- Open the
pusherinstance.phpfile. 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.
- Go to the API Access page and take the Pastable HTML code, place it in your view.
- 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.
- 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.
- 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.
- 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