You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel设置BROADCAST_CONNECTION为Pusher却始终使用log广播驱动的问题求助

Laravel设置BROADCAST_CONNECTION为Pusher却始终使用log广播驱动的问题求助

我最近在Laravel项目里尝试把广播驱动换成Pusher,已经在.env文件里设置了BROADCAST_CONNECTION=pusher,而且broadcasting.php里的默认配置也是读取这个环境变量的,但不管怎么试,打印出来的BROADCAST_CONNECTION始终是log。其他环境变量修改后都能正常生效,唯独这个变量一直不对,实在搞不懂哪里出问题了😭

先贴一下我的配置文件内容:

.env 相关配置

BROADCAST_CONNECTION=pusher
# (BROADCAST_DRIVER is deprecated)
# BROADCAST_DRIVER=pusher
PUSHER_APP_ID="<app_id>"
PUSHER_APP_KEY="<app_key>"
PUSHER_APP_SECRET="<app_secret>"
PUSHER_APP_CLUSTER="us2"
PUSHER_SCHEME=http
PUSHER_HOST=localhost

broadcasting.php 配置

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Default Broadcaster
    |--------------------------------------------------------------------------
    |
    | This option controls the default broadcaster that will be used by the
    | framework when an event needs to be broadcast. You may set this to
    | any of the connections defined in the "connections" array below.
    |
    | Supported: "reverb", "pusher", "ably", "redis", "log", "null"
    |
    */
    'default' => env('BROADCAST_CONNECTION', 'pusher'),

    /*
    |--------------------------------------------------------------------------
    | Broadcast Connections
    |--------------------------------------------------------------------------
    |
    | Here you may define all of the broadcast connections that will be used
    | to broadcast events to other systems or over WebSockets. Samples of
    | each available type of connection are provided inside this array.
    |
    */
    'connections' => [
        'reverb' => [
            'driver' => 'reverb',
            'key' => env('REVERB_APP_KEY'),
            'secret' => env('REVERB_APP_SECRET'),
            'app_id' => env('REVERB_APP_ID'),
            'options' => [
                'host' => env('REVERB_HOST'),
                'port' => env('REVERB_PORT', 443),
                'scheme' => env('REVERB_SCHEME', 'https'),
                'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
            ],
            'client_options' => [
                // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
            ],
        ],

        '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'),
                'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com',
                'port' => env('PUSHER_PORT', 9000),
                'scheme' => env('PUSHER_SCHEME', 'http'),
                'encrypted' => true,
                'useTLS' => env('PUSHER_SCHEME', 'http') === 'http',
            ],
            'client_options' => [
                // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html
            ],
        ],

        'ably' => [
            'driver' => 'ably',
            'key' => env('ABLY_KEY'),
        ],

        'log' => [
            'driver' => 'log',
        ],

        'null' => [
            'driver' => 'null',
        ],
    ],
];

用于调试的Blade代码(listener-test.blade.php)

<!-- Debug environment variables -->
<div style="background: #f0f0f0; padding: 10px; margin: 10px 0;">
    <h4>Environment Debug:</h4>
    <p>BROADCAST_CONNECTION: {{ env('BROADCAST_CONNECTION', 'NOT_SET') }}</p>
    <p>BROADCAST_DRIVER: {{ env('BROADCAST_DRIVER', 'NOT_SET') }}</p>
    <p>Config Default: {{ config('broadcasting.default') }}</p>
</div>

我已经尝试过的解决方法:

  • 修改broadcasting.php里的默认 fallback 值(改成其他值,但还是读取到log)
  • 执行清理缓存的命令:
    • php artisan optimize:clear
    • php artisan cache:clear
    • php artisan config:clear
  • 重启了本地开发服务器

但所有操作后,页面上显示的BROADCAST_CONNECTION还是log,config('broadcasting.default')也跟着是log,完全没变化。有没有大佬遇到过类似的问题?到底是哪里可能导致这个环境变量不更新呢?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.07 07:39:36