异常:Illuminate \ Broadcasting \ BroadcastException PusherBroadcaster.php:119 中没有消息
Exception: Illuminate \ Broadcasting \ BroadcastException No message in PusherBroadcaster.php:119
Laravel 5.8
我是整个推送器功能的新手,我一直在关注本教程并进行尝试,
Create Web Notifications Using Laravel and Pusher Channels。
我一步一步地跟着它,当我通过访问测试 url 到达手动测试事件的步骤时,我收到以下异常:
Illuminate \ Broadcasting \ BroadcastException
No message
C:\wamp\www\ares\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php
代码如下:
$response = $this->pusher->trigger(
$this->formatChannels($channels), $event, $payload, $socket, true
);
if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
|| $response === true) {
return;
}
throw new BroadcastException( // <-- Exception at this line
is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
);
}
/**
* Get the Pusher SDK instance.
*
* @return \Pusher\Pusher
*/
public function getPusher()
{
return $this->pusher;
}
}
我看过其他几篇关于将 encrypted: true
更改为 encrypted: false
的堆栈溢出文章,但这似乎没有任何影响。
就像我之前在评论中提到的那样,当整个 post 出错并且不会提供响应时,就会发生这种情况。这就是第 116 行出现异常的原因。我之前改成域名了!
在我的例子中,我按照代码在 "vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php" 中找到了方法 "createPusherDriver"。在这个地方我插入了这个
var_dump($config['key']);
var_dump($config['secret']);
var_dump( $config['app_id']);
var_dump($config['options']);
exit;
注意到我的选项仍然在列表中 "host" => "localhost".
我通过执行 php artisan config:cache
删除了这些行并清除了配置缓存
在下次重新加载时,我的事件被触发并记录在控制台中。
我在 Laravel 4 天前开始工作,在实现 real-time 聊天应用程序时遇到了同样的问题。找了好多天,发现这个可能根据你Laravel的版本运行ning而不同。如果是5.8,可以通过在文件config/broadcasting.php:
的pusher.options数组中添加以下代码来解决这个问题
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
添加后,config/broadcasting.php 中的推送器数组应该如下所示。
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
],
],
然后您可以 运行 php artisan config:cache
(在某些情况下可能没有必要),最后 运行 php artisan serve
。您可以在推送器网站上查阅您的应用程序并查看发送消息后收到的事件。
希望对您有所帮助!!
在我的 Laravel 5.8 版本中完美运行。但是 encrypted' => true
或 encrypted' => false
在这种情况下对于这样的 Laravel 版本并不重要。但是,根据 PUSHER 的建议,我开始广播:'useTLS' => true,
.
这是我的最终结果:
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'useTLS' => true,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
]
如果您在本地主机上工作,请尝试设置您的 .env 文件。
设置:
APP_URL=http://localhost
DB_HOST=localhost
和运行
php artisan config:cache
感谢亲爱的@Bitart
'useTLS' => true
选项解决了我的问题。
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
]
Laravel 5.8
我是整个推送器功能的新手,我一直在关注本教程并进行尝试,
Create Web Notifications Using Laravel and Pusher Channels。
我一步一步地跟着它,当我通过访问测试 url 到达手动测试事件的步骤时,我收到以下异常:
Illuminate \ Broadcasting \ BroadcastException No message
C:\wamp\www\ares\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php
代码如下:
$response = $this->pusher->trigger(
$this->formatChannels($channels), $event, $payload, $socket, true
);
if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
|| $response === true) {
return;
}
throw new BroadcastException( // <-- Exception at this line
is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
);
}
/**
* Get the Pusher SDK instance.
*
* @return \Pusher\Pusher
*/
public function getPusher()
{
return $this->pusher;
}
}
我看过其他几篇关于将 encrypted: true
更改为 encrypted: false
的堆栈溢出文章,但这似乎没有任何影响。
就像我之前在评论中提到的那样,当整个 post 出错并且不会提供响应时,就会发生这种情况。这就是第 116 行出现异常的原因。我之前改成域名了!
在我的例子中,我按照代码在 "vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php" 中找到了方法 "createPusherDriver"。在这个地方我插入了这个
var_dump($config['key']);
var_dump($config['secret']);
var_dump( $config['app_id']);
var_dump($config['options']);
exit;
注意到我的选项仍然在列表中 "host" => "localhost".
我通过执行 php artisan config:cache
在下次重新加载时,我的事件被触发并记录在控制台中。
我在 Laravel 4 天前开始工作,在实现 real-time 聊天应用程序时遇到了同样的问题。找了好多天,发现这个可能根据你Laravel的版本运行ning而不同。如果是5.8,可以通过在文件config/broadcasting.php:
的pusher.options数组中添加以下代码来解决这个问题'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
添加后,config/broadcasting.php 中的推送器数组应该如下所示。
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
],
],
然后您可以 运行 php artisan config:cache
(在某些情况下可能没有必要),最后 运行 php artisan serve
。您可以在推送器网站上查阅您的应用程序并查看发送消息后收到的事件。
希望对您有所帮助!!
在我的 Laravel 5.8 版本中完美运行。但是 encrypted' => true
或 encrypted' => false
在这种情况下对于这样的 Laravel 版本并不重要。但是,根据 PUSHER 的建议,我开始广播:'useTLS' => true,
.
这是我的最终结果:
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'useTLS' => true,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],
]
如果您在本地主机上工作,请尝试设置您的 .env 文件。
设置:
APP_URL=http://localhost
DB_HOST=localhost
和运行
php artisan config:cache
感谢亲爱的@Bitart
'useTLS' => true
选项解决了我的问题。
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
]