Building Real-Time Laravel Apps with Pusher

Debugging your server-side integration with Pusher

For the moment this section only covers debugging your integration via the Laravel Pusher Bridge.

The Pusher PHP library provides an abstraction upon the underlying HTTP requests that are made to Pusher in order to do things like trigger events. Sometimes things go wrong or we make mistakes. So it can be really handy to be able to know what's going on "under the hood" within the library.

This section provides a way of logging the Pusher library debug output to the Laravel logs. There may be alternative way of doing this, so please speak to the instructor or submit a pull request if you have any ideas. Hopefully things will become a bit easier in the future.

Adding Pusher Logging via the AppServiceProvider

Open up app/Providers/AppServiceProvider.php and update it to look as follows:

use Illuminate\Support\Facades\Log;

class LaravelLoggerProxy {
    public function log( $msg ) {

class AppServiceProvider extends ServiceProvider

    public function boot()
        $pusher = $this->app->make('pusher');
        $pusher->set_logger( new LaravelLoggerProxy() );


In the code above we're using the Log facade, creating a LaravelLoggerProxy that uses the facade and setting an instance of this class as the logger within the AppServiceProvider-boot function.

Open up storage/logs/laravel.log, delete the contents and save the file. Then load http://localhost:8000/bridge in a browser tab. Take a look at the laravel.log file now (depending no your editor you may need to re-open the file). It will now contain logging similar to the following:

[2015-08-17 12:45:13] local.INFO: Pusher: ->trigger received string channel "test-channel". Converting to array.  
[2015-08-17 12:45:13] local.INFO: Pusher: curl_init( )  
[2015-08-17 12:45:13] local.INFO: Pusher: trigger POST: {"name":"test-event","data":"{\"text\":\"Preparing the Pusher workshop!\"}","channels":["test-channel"]}  
[2015-08-17 12:45:13] local.INFO: Pusher: exec_curl response: Array
    [body] => {}
    [status] => 200

This logging shows us the interaction that took place with the Pusher HTTP API and the response.

If - at the end of this whole getting started chapter - you have some spare time, it might be worth taking a look at setting up the Laravel Debug Bar.

Where next?

Now that you've set up your logging and you know how to view the log output we're ready to move to the client and look at integrating the Pusher JS library.