PHP와 자바 스크립트로 푸셔를 구현하고 싶습니다.
composer와 함께 PHP 용 푸셔 라이브러리를 포함했습니다.
그리고 내 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' );
그리고 자바 스크립트에서
<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' );
문제를 발견했습니다.
클러스터를 추가하는 것을 잊었습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다