Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Websockets not working with pusher-php-server 7.2 #1041

Closed
szabrzyski opened this issue Oct 5, 2022 · 35 comments
Closed

Websockets not working with pusher-php-server 7.2 #1041

szabrzyski opened this issue Oct 5, 2022 · 35 comments

Comments

@szabrzyski
Copy link

Hello, after pusher-php-server has been updated to version 7.2 websockets stopped working. I'm using Laravel Echo and the initial connection to private channel is successful, but then I'm not getting any events broadcasted on that channel. With pusher-php-server 7.0.2 everything works fine. Is the new version incompatible with Laravel Websockets and should I wait for an update?

@dunakov
Copy link

dunakov commented Oct 6, 2022

I also lowered version for stable work laravel-websockets)

@mankms
Copy link

mankms commented Oct 9, 2022

Workaround

composer require pusher/pusher-php-server:7.0.2

@Nielson
Copy link

Nielson commented Oct 11, 2022

Holy shit. Thanks @szabrzyski ! I've been struggling with this for 1½ weeks now and couldn't figure out why my client side didn't catch the event.

@LipeApp
Copy link

LipeApp commented Oct 11, 2022

Когда планируется обновления? На 7.2 много чего который хотели бы пробовать.

@luceos
Copy link

luceos commented Oct 12, 2022

I have traced the issue to this: https://github.com/pusher/pusher-http-php/pull/329/files#r993378977

TLDR, the new payload for when dispatching to one channel is channel not channels.

@madpilot78
Copy link

Also experiencing this issue.

A bug report has been filed also at pusher/pusher-http-php#351

@luceos Strange, actually beyondcode/laravel-websockets does accept both channel and channels:

if ($request->has('channel')) {

Have you actually tested a patch that solves the issue?

@luceos
Copy link

luceos commented Oct 14, 2022

I don't know then @madpilot78; truth be told I have a fork because I needed a custom implementation for a @flarum extension. And in this fork it now works. Diffing the last version with the new one, and testing things locally, only the channel change has been the most apparent one.

The code you mentioned, which correctly adds the ability to read channel if it is set, was only merged into master 8 days ago, whereas the last release is from March for 1.x. I assume that's the culprit, these changes haven't been released yet and so any published version of this package will still only allow channels in the payload.

@madpilot78
Copy link

I don't know then @madpilot78; truth be told I have a fork because I needed a custom implementation for a @flarum extension. And in this fork it now works. Diffing the last version with the new one, and testing things locally, only the channel change has been the most apparent one.

No you're probably right, I'm going to test again.

The code you mentioned, which correctly adds the ability to read channel if it is set, was only merged into master 8 days ago, whereas the last release is from March for 1.x. I assume that's the culprit, these changes haven't been released yet and so any published version of this package will still only allow channels in the payload.

Oh, sorry, my bad I did not check when it was added. Then I'll test using code with that addition, maybe forcing using the repo head.

@madpilot78
Copy link

I've tested and filed pull request #1046 against branch 1.x that should fix the issue.

Thanks to @luceos for pointing me in the right direction.

@vnestoruk
Copy link

Two days that will never come back 😓 Thanks guys, at least you saved my nerves 🫡

@tomvo
Copy link

tomvo commented Oct 19, 2022

thanks @madpilot78 for fixing this, we're currently struggling with this issue on production. Any timeline on when this will be merged and tagged?

@octhavio
Copy link

composer require pusher/pusher-php-server:7.0.2

Thank you so much! I've been stuck on this issue for days. You are my hero. I consider you from now on one of my closest friends. We're practically family now.

@Wernke96
Copy link

@mpociot since we got this package merge in is there any chance we could make a release for this?

@gavinsbtm
Copy link

2 days of my life wasted... Thank god I found this page before the weekend.

Thanks to Bvanhaastrecht

@vutungf
Copy link

vutungf commented Oct 27, 2022

2 days of my life wasted... Thank god I found this page before the weekend.

me too 👍

@bci24
Copy link

bci24 commented Oct 27, 2022

in laravel 9.37 with laravel-websockets 1.13.1 the solutions was downgrading to pusher-php-server 7.0.2 or use the latest pusher-php-server 7.2.1 and manually patch the TriggerEventController from here fe78daf

@tomvo
Copy link

tomvo commented Oct 27, 2022

@bci24 a better fix would be to use "beyondcode/laravel-websockets": "1.x-dev", in your composer instead of manually patching stuff.

@jafar690
Copy link

Spent 4 hours debugging the same issue, 4 hours i won't get back. thanks @mankms

@medilies
Copy link

medilies commented Oct 29, 2022

Spent the whole day editing configs and changing the composer file to figure out that V7.2 is broken is the source of the problem medilies/messenger-clone@6f60c31...a5223dd

Now the question is. Should we expect an update soon?

bpotmalnik added a commit to bpotmalnik/valuto-api that referenced this issue Oct 30, 2022
@lordjoo
Copy link

lordjoo commented Oct 30, 2022

I've downgrade the pusher-php-server and still the client doesn't catch the events abd in the dashboard they didn't appear too

@lordjoo
Copy link

lordjoo commented Oct 30, 2022

I've ended up switching to soketi

@kamilkahar90
Copy link

Looking forward to this issue being resolved. Downgrade pusher-php-server to 7.0.2 working for me.

@Slauta
Copy link

Slauta commented Nov 1, 2022

I spent a day, but downgrade to 7.0.2 helped me

@Steffra
Copy link

Steffra commented Nov 5, 2022

Unfortunately i've only found this issue after i've already resolved it by myself. Downgrading to 7.0.2 is the only thing that has worked for me.
Can't wait untill it's fixed!

@DanJamesMills
Copy link

DanJamesMills commented Nov 8, 2022

I had the same issue guys been debugging until this afternoon to find this thread, has anyone created a pull request to fix this or should I create one?

@kluevandrew
Copy link

A best way to fix:

./vendor/beyondcode/laravel-websockets/src/HttpApi/Controllers/TriggerEventController.php

<?php

namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;

use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use Illuminate\Http\Request;

class TriggerEventController extends Controller
{
    public function __invoke(Request $request)
    {
        $this->ensureValidSignature($request);

        $channels = $request->json()->get('channels', []);
        $channel = $request->json()->get('channel');
        if ($channel) {
            $channels[] = $channel;
        }
        foreach ($channels as $channelName) {
            $channel = $this->channelManager->find($request->appId, $channelName);

            optional($channel)->broadcastToEveryoneExcept([
                'channel' => $channelName,
                'event' => $request->json()->get('name'),
                'data' => $request->json()->get('data'),
            ], $request->json()->get('socket_id'));

            DashboardLogger::apiMessage(
                $request->appId,
                $channelName,
                $request->json()->get('name'),
                $request->json()->get('data')
            );

            StatisticsLogger::apiMessage($request->appId);
        }

        return (object) [];
    }
}

@madpilot78
Copy link

A best way to fix:

./vendor/beyondcode/laravel-websockets/src/HttpApi/Controllers/TriggerEventController.php
[...]

@kluevandrew You suggested patch looks very similar to mine from #1046, which has already been merged to the 1.x branch.

Unluckily until a new release is cut from 1.x the change is not going to be distributed automatically.

Let's hope a new 1.x release is cut soon.

@AliKhedmati
Copy link

I still had the issue with v7.2.1
Downgrading to v7.0.2 was working fine for me.

@madpilot78
Copy link

@AliKhedmati

The issue is in beyondcode/laravel-websockets. pusher/pusher-http-php has changed how it accesses its own API and is not going back, they have no reason too, they do not support servers except their own.

beyondcode/laravel-websockets needs to adapt to the new way the client accesses the API.

@tomvo
Copy link

tomvo commented Nov 29, 2022

I don't understand why the fix is merged but not a new release being tagged. Is this repo even maintained? @mpociot

@danh65
Copy link

danh65 commented Nov 29, 2022

A best way to fix:

./vendor/beyondcode/laravel-websockets/src/HttpApi/Controllers/TriggerEventController.php

<?php

namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;

use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use Illuminate\Http\Request;

class TriggerEventController extends Controller
{
    public function __invoke(Request $request)
    {
        $this->ensureValidSignature($request);

        $channels = $request->json()->get('channels', []);
        $channel = $request->json()->get('channel');
        if ($channel) {
            $channels[] = $channel;
        }
        foreach ($channels as $channelName) {
            $channel = $this->channelManager->find($request->appId, $channelName);

            optional($channel)->broadcastToEveryoneExcept([
                'channel' => $channelName,
                'event' => $request->json()->get('name'),
                'data' => $request->json()->get('data'),
            ], $request->json()->get('socket_id'));

            DashboardLogger::apiMessage(
                $request->appId,
                $channelName,
                $request->json()->get('name'),
                $request->json()->get('data')
            );

            StatisticsLogger::apiMessage($request->appId);
        }

        return (object) [];
    }
}

This worked for me. Glad to find a solution after spending more than a day troubleshooting!

@Msangi21
Copy link

Workaround

composer require pusher/pusher-php-server:7.0.2

You saved my 3 days

@099912
Copy link

099912 commented Aug 9, 2023

"php": "^8.0",
"beyondcode/laravel-websockets": "^2.0@beta",
"cboden/ratchet": "^0.4.4",
"cviebrock/eloquent-sluggable": "^9.0",
"fruitcake/laravel-cors": "^2.0.5",
"guzzlehttp/guzzle": "^7.7",
"illuminate/session": "*",
"laravel/framework": "^9.0",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.7",
"pusher/pusher-php-server": "7.0.2",
I have this version of laravel i think beta 2.o websockets doesnot work for php 8 I also downgrade the pusher from 7.2 to 7.0 but the dashboard of websocj=ket doesnot catch the event

@099912
Copy link

099912 commented Aug 9, 2023

which version of websocket should I use for
current versions (but websocket dashboard dosnot catch event)
"php": "^8.0",
"beyondcode/laravel-websockets": "^2.0@beta",
"laravel/framework": "^9.0",
"pusher/pusher-php-server": "7.0.2",

@jdthehelper
Copy link

I have create full documentation for laravel websocket with realted issue every time. Please check it https://myphpinformation.blogspot.com/2024/01/laravel-websocket-setup-and-example-how-to-use-it.html this my help you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests