PHP 和 Javascript 的推送器

Pusher with PHP And Javascript

我想用 php 和 javascript 实现推送器。

我已经为 php 的 composer 添加了推送器库。

我的 php 密码是

<?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' );

并在 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>

但是当我刷新页面时,我没有收到任何控制台日志。

知道哪里出了问题吗?

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

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

发现问题。

我忘记添加集群了。