{"id":530,"date":"2022-01-14T22:03:00","date_gmt":"2022-01-14T22:03:00","guid":{"rendered":"https:\/\/rishikantsri.in\/blog\/?p=530"},"modified":"2023-10-26T06:14:37","modified_gmt":"2023-10-26T06:14:37","slug":"config-broadcasting-php","status":"publish","type":"post","link":"https:\/\/rishikantsri.in\/blog\/config-broadcasting-php\/","title":{"rendered":"Config: broadcasting.php"},"content":{"rendered":"\n<p>The broadcasting.php file, provided here,  is from Laravel 8&#8217;s configuration for broadcasting. Broadcasting in Laravel is a feature that allows you to send events and data to multiple subscribed clients in real-time, typically used for implementing features like chat applications, notifications, and live updates. Laravel provides various broadcasting drivers to achieve this, and the code you shared is a configuration file for these drivers.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:19.80000114440918px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?php\n\nreturn [\n\n    \/*\n    |--------------------------------------------------------------------------\n    | Default Broadcaster\n    |--------------------------------------------------------------------------\n    |\n    | This option controls the default broadcaster that will be used by the\n    | framework when an event needs to be broadcast. You may set this to\n    | any of the connections defined in the &quot;connections&quot; array below.\n    |\n    | Supported: &quot;pusher&quot;, &quot;ably&quot;, &quot;redis&quot;, &quot;log&quot;, &quot;null&quot;\n    |\n    *\/\n\n    'default' =&gt; env('BROADCAST_DRIVER', 'null'),\n\n    \/*\n    |--------------------------------------------------------------------------\n    | Broadcast Connections\n    |--------------------------------------------------------------------------\n    |\n    | Here you may define all of the broadcast connections that will be used\n    | to broadcast events to other systems or over websockets. Samples of\n    | each available type of connection are provided inside this array.\n    |\n    *\/\n\n    'connections' =&gt; [\n\n        'pusher' =&gt; [\n            'driver' =&gt; 'pusher',\n            'key' =&gt; env('PUSHER_APP_KEY'),\n            'secret' =&gt; env('PUSHER_APP_SECRET'),\n            'app_id' =&gt; env('PUSHER_APP_ID'),\n            'options' =&gt; [\n                'cluster' =&gt; env('PUSHER_APP_CLUSTER'),\n                'useTLS' =&gt; true,\n            ],\n        ],\n\n        'ably' =&gt; [\n            'driver' =&gt; 'ably',\n            'key' =&gt; env('ABLY_KEY'),\n        ],\n\n        'redis' =&gt; [\n            'driver' =&gt; 'redis',\n            'connection' =&gt; 'default',\n        ],\n\n        'log' =&gt; [\n            'driver' =&gt; 'log',\n        ],\n\n        'null' =&gt; [\n            'driver' =&gt; 'null',\n        ],\n\n    ],\n\n];\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">&lt;?<\/span><span style=\"color: #B392F0\">php<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> [<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">    <\/span><span style=\"color: #6B737C\">\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    |--------------------------------------------------------------------------<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    | Default Broadcaster<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    |--------------------------------------------------------------------------<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    |<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    | This option controls the default broadcaster that will be used by the<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    | framework when an event needs to be broadcast. You may set this to<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    | any of the connections defined in the &quot;connections&quot; array below.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    |<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    | Supported: &quot;pusher&quot;, &quot;ably&quot;, &quot;redis&quot;, &quot;log&quot;, &quot;null&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    |<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    *\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">    <\/span><span style=\"color: #FFAB70\">&#39;default&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> env<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;BROADCAST_DRIVER&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&#39;null&#39;<\/span><span style=\"color: #BBBBBB\">),<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">    <\/span><span style=\"color: #6B737C\">\/*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    |--------------------------------------------------------------------------<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    | Broadcast Connections<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    |--------------------------------------------------------------------------<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    |<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    | Here you may define all of the broadcast connections that will be used<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    | to broadcast events to other systems or over websockets. Samples of<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    | each available type of connection are provided inside this array.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    |<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\">    *\/<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">    <\/span><span style=\"color: #FFAB70\">&#39;connections&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> [<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">        <\/span><span style=\"color: #FFAB70\">&#39;pusher&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;driver&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&#39;pusher&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;key&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> env<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;PUSHER_APP_KEY&#39;<\/span><span style=\"color: #BBBBBB\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;secret&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> env<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;PUSHER_APP_SECRET&#39;<\/span><span style=\"color: #BBBBBB\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;app_id&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> env<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;PUSHER_APP_ID&#39;<\/span><span style=\"color: #BBBBBB\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;options&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">                <\/span><span style=\"color: #FFAB70\">&#39;cluster&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> env<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;PUSHER_APP_CLUSTER&#39;<\/span><span style=\"color: #BBBBBB\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">                <\/span><span style=\"color: #FFAB70\">&#39;useTLS&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            ]<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">        ]<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">        <\/span><span style=\"color: #FFAB70\">&#39;ably&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;driver&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&#39;ably&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;key&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> env<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;ABLY_KEY&#39;<\/span><span style=\"color: #BBBBBB\">),<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">        ]<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">        <\/span><span style=\"color: #FFAB70\">&#39;redis&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;driver&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&#39;redis&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;connection&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&#39;default&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">        ]<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">        <\/span><span style=\"color: #FFAB70\">&#39;log&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;driver&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&#39;log&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">        ]<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">        <\/span><span style=\"color: #FFAB70\">&#39;null&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">            <\/span><span style=\"color: #FFAB70\">&#39;driver&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&#39;null&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">        ]<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">    ]<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">];<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Let&#8217;s break down this code step by step, discussing its syntax, usage, providing a demo, and talking about the pros and cons.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Default Broadcaster<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.899993896484375px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"'default' =&gt; env('BROADCAST_DRIVER', 'null'),\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #FFAB70\">&#39;default&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> env<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #FFAB70\">&#39;BROADCAST_DRIVER&#39;<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&#39;null&#39;<\/span><span style=\"color: #BBBBBB\">),<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This line defines the default broadcasting driver to be used in your application. It uses the value of the <code>BROADCAST_DRIVER<\/code> environment variable. If this variable is not set, it defaults to <code>'null'<\/code>. The default driver is the one that Laravel will use when broadcasting events unless explicitly specified otherwise.<\/p>\n\n\n\n<p><strong>Syntax Explanation:<\/strong><\/p>\n\n\n\n<ul>\n<li><code>'default'<\/code> is the key for the default broadcaster configuration.<\/li>\n\n\n\n<li><code>env('BROADCAST_DRIVER', 'null')<\/code> is a way to fetch the value of the <code>BROADCAST_DRIVER<\/code> environment variable. If it&#8217;s not set, it defaults to <code>'null'<\/code>.<\/li>\n<\/ul>\n\n\n\n<p><strong>Usage:<\/strong><\/p>\n\n\n\n<ul>\n<li>This configuration setting allows you to change the default broadcasting driver for your Laravel application. You can set it to one of the drivers defined in the <code>'connections'<\/code> section.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Broadcast Connections<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.90000057220459px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"'connections' =&gt; [\n    \/\/ ...\n]\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #FFAB70\">&#39;connections&#39;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">=&gt;<\/span><span style=\"color: #B392F0\"> [<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">    <\/span><span style=\"color: #6B737C\">\/\/ ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This section defines different broadcasting drivers that can be used. Laravel supports several broadcasting drivers, including Pusher, Ably, Redis, Log, and Null.<\/p>\n\n\n\n<p><strong>Syntax Explanation:<\/strong><\/p>\n\n\n\n<ul>\n<li><code>'connections'<\/code> is an array that contains configurations for different broadcasting drivers.<\/li>\n\n\n\n<li>Inside this array, you&#8217;ll find configurations for each driver, such as &#8216;pusher&#8217;, &#8216;ably&#8217;, &#8216;redis&#8217;, &#8216;log&#8217;, and &#8216;null&#8217;.<\/li>\n<\/ul>\n\n\n\n<p><strong>Usage:<\/strong><\/p>\n\n\n\n<ul>\n<li>Laravel allows you to configure multiple broadcasting connections, and you can choose which one to use for specific use cases within your application. For example, you might use the Pusher driver for a real-time chat feature and the Log driver for debugging purposes.<\/li>\n<\/ul>\n\n\n\n<p>Now, let&#8217;s discuss each of the broadcasting drivers briefly:<\/p>\n\n\n\n<ol>\n<li><strong>Pusher:<\/strong>\n<ul>\n<li>The Pusher driver uses Pusher, a third-party service, to provide real-time functionality. You need to provide your Pusher app key, secret, app ID, and other options in the configuration.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Ably:<\/strong>\n<ul>\n<li>The Ably driver uses the Ably service for real-time messaging. You need to provide your Ably key in the configuration.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Redis:<\/strong>\n<ul>\n<li>The Redis driver uses Redis as a backend for broadcasting. You can configure the Redis connection in Laravel&#8217;s <code>.env<\/code> file.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Log:<\/strong>\n<ul>\n<li>The Log driver is mainly for debugging and logging. It doesn&#8217;t actually broadcast events but logs them to Laravel&#8217;s log files.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Null:<\/strong>\n<ul>\n<li>The Null driver is essentially a &#8220;no-op&#8221; driver that doesn&#8217;t broadcast events. It&#8217;s useful for development and testing when you don&#8217;t want to send events to any real broadcasting service.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Demo<\/h3>\n\n\n\n<p>Let&#8217;s demonstrate how to use the broadcasting configuration in a Laravel application. For this example, we&#8217;ll use the Pusher driver as it&#8217;s a popular choice for real-time features.<\/p>\n\n\n\n<ol>\n<li><strong>Setup Environment Variables:<\/strong><br>In your <code>.env<\/code> file, set the following environment variables with your Pusher credentials:<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.899993896484375px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   BROADCAST_DRIVER=pusher\n   PUSHER_APP_ID=your_app_id\n   PUSHER_APP_KEY=your_app_key\n   PUSHER_APP_SECRET=your_app_secret\n   PUSHER_APP_CLUSTER=your_cluster\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   BROADCAST_DRIVER<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\">pusher<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   PUSHER_APP_ID<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\">your_app_id<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   PUSHER_APP_KEY<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\">your_app_key<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   PUSHER_APP_SECRET<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\">your_app_secret<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">   PUSHER_APP_CLUSTER<\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\">your_cluster<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"2\">\n<li><strong>Create an Event:<\/strong><br>Create an event class (e.g., <code>RealTimeEvent<\/code>) using Laravel&#8217;s <code>php artisan<\/code> command:<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.899993896484375px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   php artisan make:event RealTimeEvent\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   php artisan make:event RealTimeEvent<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this event class, you can define the data you want to broadcast.<\/p>\n\n\n\n<ol start=\"3\">\n<li><strong>Broadcast the Event:<\/strong><br>In your controller or other code, broadcast the event using Laravel&#8217;s built-in broadcasting methods. For example:<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:1.125rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:9.88751220703125px;line-height:1.625rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1f1f1f\"><span style=\"background:#a37ced;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1f1f1f\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"   event(new RealTimeEvent($data));\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">   event<\/span><span style=\"color: #BBBBBB\">(<\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">RealTimeEvent<\/span><span style=\"color: #B392F0\">($data)<\/span><span style=\"color: #BBBBBB\">)<\/span><span style=\"color: #B392F0\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"4\">\n<li><strong>Client-Side Setup:<\/strong><br>On the client side, you&#8217;ll need to use a JavaScript library (e.g., Laravel Echo) to subscribe to the event and react to it in real-time.<\/li>\n\n\n\n<li><strong>Receive Real-Time Data:<\/strong><br>With the Pusher driver and proper JavaScript setup, your client application will receive real-time data when the <code>RealTimeEvent<\/code> is triggered.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Pros and Cons<\/h3>\n\n\n\n<p><strong>Pros:<\/strong><\/p>\n\n\n\n<ol>\n<li><strong>Real-Time Updates:<\/strong> Broadcasting allows you to push data to clients in real-time, which is essential for building features like chat, notifications, live updates, and online gaming.<\/li>\n\n\n\n<li><strong>Scalability:<\/strong> By using third-party services like Pusher or Ably, you offload the burden of managing real-time connections and scaling your application.<\/li>\n\n\n\n<li><strong>Extensible:<\/strong> Laravel&#8217;s broadcasting system is highly extensible. You can create custom broadcasting drivers if you have specific requirements.<\/li>\n\n\n\n<li><strong>Integration:<\/strong> Laravel provides seamless integration with various broadcasting services, making it easy to set up real-time features.<\/li>\n<\/ol>\n\n\n\n<p><strong>Cons:<\/strong><\/p>\n\n\n\n<ol>\n<li><strong>Complexity:<\/strong> Implementing broadcasting can be complex, especially when dealing with multiple drivers and client-side libraries.<\/li>\n\n\n\n<li><strong>Cost:<\/strong> Some third-party broadcasting services like Pusher may incur costs based on usage. This should be considered when choosing a driver.<\/li>\n\n\n\n<li><strong>Server Resources:<\/strong> Real-time features can put a strain on your server resources, so proper scaling and optimization are crucial.<\/li>\n\n\n\n<li><strong>Learning Curve:<\/strong> If you&#8217;re new to broadcasting and real-time web applications, there can be a learning curve in setting up and managing the infrastructure.<\/li>\n<\/ol>\n\n\n\n<p>In summary, Laravel&#8217;s broadcasting system is a powerful tool for adding real-time functionality to your applications. It offers various drivers for flexibility, and you can choose the one that best fits your needs. However, it&#8217;s essential to consider the complexity and potential costs associated with real-time features before implementing them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The broadcasting.php file, provided here, is from Laravel 8&#8217;s configuration for broadcasting. Broadcasting in Laravel is a feature that allows you to send events and data to multiple subscribed clients in real-time, typically used for implementing features like chat applications, notifications, and live updates. Laravel provides various broadcasting drivers to achieve this, and the code [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[63,71,11],"tags":[72,61,3,4],"_links":{"self":[{"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts\/530"}],"collection":[{"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/comments?post=530"}],"version-history":[{"count":2,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts\/530\/revisions"}],"predecessor-version":[{"id":533,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/posts\/530\/revisions\/533"}],"wp:attachment":[{"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/media?parent=530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/categories?post=530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rishikantsri.in\/blog\/wp-json\/wp\/v2\/tags?post=530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}