I'm trying to integrate web socket into my laravel project. I did all steps from here
composer require pusher/pusher-php-server
/Users/alpha/Sites/jdoe/config/broadcasting.php
https://dashboard.pusher.com/apps/888
app_id = "888"
key = "***"
secret = "333"
cluster = "us2"
|
V
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=888
PUSHER_APP_KEY=***
PUSHER_APP_SECRET=333
PUSHER_APP_CLUSTER=us2
.env.example + .env
npm install --save laravel-echo pusher-js
npm run watch
I tested making a post to my /ws/log
{-code-2}
I kept getting
ErrorException: array_merge(): Expected parameter 2 to be an array, {-code-4} given in file /Users/alpha/Sites/jdoe/vendor/pusher/pusher-php-server/src/Pusher.php on line 518
I opened that file
{-code-3}
$params some how ={-code-4}
How do I continue to debug this further?
I removed my vendor/ and tried version 4.1 as suggested.
{-code-5}
I still face issue when making a POST to my route via POSTman.
So for this problem, in fact that was an issue in Laravel and it is solved now
using (laravel 8.29.0) or higher versions.
So pusher-http-php library v5.0.1 and Laravel v8.29.0 will work fine for you.
Another Solution: is to downgrade pusher to version 4.1 on composer.json and this version seems to work fine with older laravel versions (older than 8.29.0).
If you want to solve the problem with your current installation:
The problem is that the calls for trigger function, at least on laravel 8 is not sending the right parameters, so inPusherBroadcaster.php
andpusher-php-server/Pusher.php
there are 2 calls for trigger function which are:
$this->pusher->trigger(
$this->formatChannels($channels), $event, $payload, $socket, true
);
and
public function trigger($channels, $event, $data, $params = array(), $already_encoded = false)
You will need to change thePusher
only.
1- Change (Line 496).
$data_encoded = $this->crypto->encrypt_payload($channels[0], $already_encoded ? $data : json_encode($data));
To:
$data_encoded = $this->crypto->encrypt_payload($channels[0], $already_encoded && !is_array( $data) ? $data : json_encode($data));
2- Change (Line 499).
$data_encoded = $already_encoded ? $data : json_encode($data);
To:
$data_encoded = $already_encoded && !is_array( $data) ? $data : json_encode($data);
3- Change (Line 518)
$all_params = array_merge($post_params, $params);
To:
$all_params = array_merge($post_params, is_array($params) ? $params:[]);
4- Change (Line 542)
return $result;
To:
return $response;
and this will make it works for you fine.
Note: As I said it is resolved in v8.29.0 of Laravel. Link
Note: Or you can usecomposer require pusher/pusher-php-server ^4.1
Note that:
The main problem is that$param
isnull
in this case and it didn't check if this value isarray()
so when the code tries to mergearray()
withnull
.
Resources:
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
Bootstrap is not exclusively a CSS framework, but its most popular features are CSS-centric. These include a powerful grid, icons, buttons, map components, navigation bars, and more.
https://getbootstrap.com/
Foundation, similar to Bootstrap, has become very popular as a more complex framework with some advanced but easy-to-implement CSS components. It is built with Sass, so just like Bootstrap, it is customizable. In addition to this, it also boasts some features that help make the design mobile responsive.
https://get.foundation/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.