Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pusher in php - Do not send events [ Unknown auth_key]

Tags:

php

pusher

I am using the following code:

 require('pusher-http-php-master/lib/Pusher.php');
error_reporting(E_ALL);
$app_id = '*'; 
$app_key = '*';
$app_secret = '*';

class MyLogger {
  public function log( $msg ) {
    print_r( $msg . "<br />" );
  }
}
$pusher = new Pusher($app_key, $app_secret, $app_id);
$logger = new MyLogger();
$pusher->set_logger( $logger );
$data['message'] = 'hello world';
$result = $pusher->trigger('test_channel', 'my_event', array( 'hello' => 'world' ));
$logger->log( "---- My Result ---" );
$logger->log( $result );

And the answer I have is:

Pusher: ->trigger received string channel "test_channel". Converting to array. Pusher: create_curl( http://api.pusherapp.com:80/apps/*/events?auth_key=*&auth_signature=*&auth_timestamp=*&auth_version=1.0&body_md5=*) Pusher: trigger POST: {"name":"my_event","data":"{\"hello\":\"world\"}","channels":["test_channel"]} Pusher: exec_curl response: Array ( [body] => Unknown auth_key [status] => 400 ) ---- My Result ---

What am I doing wrong?

What I want is to send notifications from the server.

like image 617
Luis Ramos Avatar asked Feb 07 '23 07:02

Luis Ramos


2 Answers

I suspect your cluster might be wrong.

When you create a Pusher application on dashboard.pusher.com, you're asked to choose a cluster:

enter image description here

pusher-http-php-master connects to mt1 (us-east-1) by default. If you chose another cluster - like eu (eu-west-1) - you'll need to be explicit:

$pusher = new Pusher(
  $app_key,
  $app_secret,
  $app_id,
  array( 'cluster' => 'eu' ) 
);

If that doesn't work, I would double triple check your $app_secret.

like image 179
Alex Booker Avatar answered Feb 08 '23 21:02

Alex Booker


I had the same problem when i was using Pusher with Lumen. For me what worked was i removed the package from composer and reinstalled the package.

first

composer remove pusher/pusher-php-server

then

composer require pusher/pusher-php-server
like image 20
Pramod Avatar answered Feb 08 '23 20:02

Pramod