humbleiam
humbleiam

Reputation: 1009

Pusher with PHP And Javascript

I want to implement pusher with php and javascript.

I have included pusher library for php with composer.

And my php code is

<?php
require_once "vendor/autoload.php";

$app_id = "XX";
$app_key = "XX";
$app_secret = "XX";
$cluster = "ap1";

$pusher = new Pusher( $app_key, $app_secret, $app_id, array( 'encrypted' => true ) );

$pusher->trigger( 'XX-channel', 'test', 'hello world' );

And in javascript

<head>
    <title>Pusher</title>
    <script src="https://js.pusher.com/4.1/pusher.min.js"></script>

</head>
<body>

<script type="text/javascript">
        const socket = new Pusher("XXX", {
            cluster: 'ap1'
        });
        const channel = socket.subscribe('XX-channel');

        channel.bind('test', function (data) {
          console.log(data);
        });
    </script>
</body>

But when I refresh page I dont receive any console logs.

Any idea what might be wrong?

Upvotes: 0

Views: 660

Answers (1)

humbleiam
humbleiam

Reputation: 1009

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

$pusher->trigger( 'XX-channel', 'test', 'hello world' );

Found issue.

I forgot to add cluster.

Upvotes: 1

Related Questions