\r\n \r\n \r\n \r\n\r\n\r\n

Pusher Test

\r\n

\r\n 別ブラウザ(タブ)で/helloにアクセスすると、右端から通知が出現します。\r\n

\r\n\r\n\r\n```\r\napp/Event/HelloPusher.php\r\n```ここに言語を入力\r\nmessage = $message;\r\n }\r\n\r\n /**\r\n * 送信先のチャンネル\r\n * @return \\Illuminate\\Broadcasting\\Channel|array\r\n */\r\n public function broadcastOn()\r\n {\r\n return ['my-channel'];\r\n }\r\n\r\n /**\r\n * イベント名\r\n * @return string\r\n */\r\n public function broadcastAs()\r\n {\r\n return 'my-event';\r\n }\r\n}\r\n```\r\n\r\npusherサイト側のログでは\r\nSubscribed Channel: my-channel Socket ID: xxxxxx 13:26:30\r\nConnection Origin: Socket ID: xxxxxx 13:26:30\r\nのようになっています\r\n\r\nエラー情報の追記\r\n```ここに言語を入力\r\n[2021-02-27 22:43:51] develop.ERROR: array_merge(): Argument #2 is not an array {\"exception\":\"[object] (ErrorException(code: 0): array_merge(): Argument #2 is not an array at /var/www/html/develop/vendor/pusher/pusher-php-server/src/Pusher.php:518)\r\n[stacktrace]\r\n#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'array_merge(): ...', '/var/www/html/d...', 518, Array)\r\n#1 /var/www/html/develop/vendor/pusher/pusher-php-server/src/Pusher.php(518): array_merge(Array, NULL)\r\n#2 /var/www/html/develop/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php(113): Pusher\\Pusher->trigger(Array, 'my-event', Array, NULL, true)\r\n#3 /var/www/html/develop/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(64): Illuminate\\Broadcasting\\Broadcasters\\PusherBroadcaster->broadcast(Array, 'my-event', Array)\r\n#4 /var/www/html/develop/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Broadcasting\\BroadcastEvent->handle(Object(Illuminate\\Broadcasting\\Broadcasters\\PusherBroadcaster))\r\n```\r\nまだまだ続くのですが\r\n\r\nバージョン追記\r\nLaravel 6.20.6\r\n\"pusher/pusher-php-server\": \"Required to use the Pusher broadcast driver (^4.0).\",\r\nとなっています\r\n\r\nコンソールに出ていたもの\r\n```ここに言語を入力\r\nPusher : State changed : connecting -> connected with new socket ID \r\npusher.min.js:8 Pusher : Event sent : {\"event\":\"pusher:subscribe\",\"data\":{\"channel\":\"my-channel\"}}\r\npusher.min.js:8 Pusher : Event recd : {\"event\":\"pusher_internal:subscription_succeeded\",\"data\":{},\"channel\":\"my-channel\"}\r\npusher.min.js:8 Pusher : No callbacks on my-channel for pusher:subscription_succeeded\r\npusher.min.js:8 Pusher : Event sent : {\"event\":\"pusher:ping\",\"data\":{}}\r\n\r\n```","answerCount":1,"upvoteCount":0,"datePublished":"2021-02-27T13:24:23.369Z","dateModified":"2021-02-27T15:21:37.691Z","acceptedAnswer":{"@type":"Answer","text":"pusher/pusher-php-serverのバージョンが合っていないのではないでしょうか。\r\nバージョン4をインストールし直すとどうでしょうか。\r\n\r\n```\r\ncomposer require pusher/pusher-php-server \"~4.0\"\r\n```\r\n\r\n参考: [Pusherチャンネル](https://readouble.com/laravel/6.x/ja/broadcasting.html#driver-prerequisites)","dateModified":"2021-02-27T15:30:47.825Z","datePublished":"2021-02-27T15:30:47.825Z","upvoteCount":0,"url":"https://teratail.com/questions/325069#reply-450596"},"suggestedAnswer":[],"breadcrumb":{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"https://teratail.com","name":"トップ"}},{"@type":"ListItem","position":2,"item":{"@id":"https://teratail.com/tags/Laravel","name":"Laravelに関する質問"}},{"@type":"ListItem","position":3,"item":{"@id":"https://teratail.com/questions/325069","name":"pusherを使う過程でエラー array_merge(): Argument #2 is not an array"}}]}}}
質問するログイン新規登録

Q&A

解決済

1回答

3626閲覧

pusherを使う過程でエラー array_merge(): Argument #2 is not an array

creative_09

総合スコア80

Laravel

LaravelとはTaylor Otwellによって開発された、オープンソースなPHPフレームワークです。Laravelはシンプルで表現的なシンタックスを持ち合わせており、ウェブアプリケーション開発の手助けをしてくれます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

0クリップ

投稿2021/02/27 13:24

編集2021/02/27 15:21

0

0

laravelでpusherを使ったことがないので、
pusherの動作確認のために、実行したところ、
array_merge(): Argument #2 is not an array
というエラーが出て、pusherの動作確認が出来ません。
pusher側のデバッグコンソールには反応があるので、疎通はしているのだと思っています。
上記のエラーの原因が全くわからず、配列になっていないエラーというのがどの場面で出ているのか教えて下さい。

web.php

Route::get('/hello', function() { event(new \App\Events\HelloPusher('テストメッセージ')); return 'hello pusher'; }); Route::get('/test2', function () { return view('test2'); })->name('test2');

test2.blade.php

<!DOCTYPE html> <head> <title>Pusher Test</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/notify/0.4.2/notify.min.js"></script> <script src="https://js.pusher.com/4.3/pusher.min.js"></script> <script> Pusher.logToConsole = true; var pusher = new Pusher('xxxxxxxxxxxxxx', { cluster: 'xxx', forceTLS: true }); //購読するチャンネルを指定 var channel = pusher.subscribe('my-channel'); //イベントを受信したら channel.bind('my-event', function(data) { $.notify(data.message, 'info'); }); </script> </head> <body> <h1>Pusher Test</h1> <p> 別ブラウザ(タブ)で/helloにアクセスすると、右端から通知が出現します。 </p> </body>

app/Event/HelloPusher.php

<?php namespace App\Events; use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PresenceChannel; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; class HelloPusher implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; public $message; /** * コンストラクタ * * @param string $message */ public function __construct($message = 'hello pusher') { $this->message = $message; } /** * 送信先のチャンネル * @return \Illuminate\Broadcasting\Channel|array */ public function broadcastOn() { return ['my-channel']; } /** * イベント名 * @return string */ public function broadcastAs() { return 'my-event'; } }

pusherサイト側のログでは
Subscribed Channel: my-channel Socket ID: xxxxxx 13:26:30
Connection Origin: Socket ID: xxxxxx 13:26:30
のようになっています

エラー情報の追記

[2021-02-27 22:43:51] develop.ERROR: array_merge(): Argument #2 is not an array {"exception":"[object] (ErrorException(code: 0): array_merge(): Argument #2 is not an array at /var/www/html/develop/vendor/pusher/pusher-php-server/src/Pusher.php:518) [stacktrace] #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'array_merge(): ...', '/var/www/html/d...', 518, Array) #1 /var/www/html/develop/vendor/pusher/pusher-php-server/src/Pusher.php(518): array_merge(Array, NULL) #2 /var/www/html/develop/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php(113): Pusher\Pusher->trigger(Array, 'my-event', Array, NULL, true) #3 /var/www/html/develop/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(64): Illuminate\Broadcasting\Broadcasters\PusherBroadcaster->broadcast(Array, 'my-event', Array) #4 /var/www/html/develop/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\Broadcasting\BroadcastEvent->handle(Object(Illuminate\Broadcasting\Broadcasters\PusherBroadcaster))

まだまだ続くのですが

バージョン追記
Laravel 6.20.6
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0).",
となっています

コンソールに出ていたもの

Pusher : State changed : connecting -> connected with new socket ID pusher.min.js:8 Pusher : Event sent : {"event":"pusher:subscribe","data":{"channel":"my-channel"}} pusher.min.js:8 Pusher : Event recd : {"event":"pusher_internal:subscription_succeeded","data":{},"channel":"my-channel"} pusher.min.js:8 Pusher : No callbacks on my-channel for pusher:subscription_succeeded pusher.min.js:8 Pusher : Event sent : {"event":"pusher:ping","data":{}}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Lulucom

2021/02/27 14:13

> array_merge(): Argument #2 is not an array どこでこのエラーが発生したのかなど、他にもたくさんの情報が出力されていると思いますので、掲載していただくとよいでしょう。その情報が無いと回答も難しいと思います。
creative_09

2021/02/27 14:28

ありがとうございます。 エラーを追記しました
phper.k

2021/02/27 14:46

Stack trace もっと出ているはずだけど、省略してません?
Lulucom

2021/02/27 14:50 編集

ありがとうございます。pusher/pusher-php-serverで起きているんですね。 以下のバージョン情報についても質問の方へ追記をお願いします。 ・pusher/pusher-php-serverパッケージのバージョン ・Laravelのバージョン 追記されるとメール通知で気付けますので、こちらに返信していただく必要はありません。
creative_09

2021/02/27 15:02

phper.kさん、文字数の制限?かなにかで書き込みが出来ないのでどうすればいいでしょうか?
Lulucom

2021/02/27 15:20 編集

pusher/pusher-php-serverのバージョンですが、見ているところが違うかもしれません。 composer show pusher/pusher-php-server の実行結果で4行目あたりを見ていただくと良いと思います。
creative_09

2021/02/27 15:23

versions : * v5.0.1となっておりました。 わざわざありがとうございます。そのやり方も勉強になりました
guest

回答1

0

ベストアンサー

pusher/pusher-php-serverのバージョンが合っていないのではないでしょうか。
バージョン4をインストールし直すとどうでしょうか。

composer require pusher/pusher-php-server "~4.0"

参考: Pusherチャンネル

投稿2021/02/27 15:30

Lulucom

総合スコア1904

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

creative_09

2021/02/27 15:43

ありがとうございます versions : * v4.1.5 となり、画面が変わりました。 Illuminate\Broadcasting\BroadcastException Pusher error: 404 NOT FOUND . となり、該当のエラー行数をみてみると throw new BroadcastException( ! empty($response['body']) ? sprintf('Pusher error: %s.', $response['body']) : 'Failed to connect to Pusher.' ); となっています
Lulucom

2021/02/27 16:01

Pusherへの接続情報を正しく設定できていますか?
creative_09

2021/02/27 17:19

もう一度確認しました。 設定ですが、間違いなくしていたつもりで何回も見直していたのですが、 ミスで、envファイルに記述するのをコードの上方と下方で2回記述しており、 下の方は設定がカラの状態でしたので、設定がないような形で上書きしておりました。 お騒がせして本当に申し訳ございません。 ありがとうございました。 無事に意図した結果が帰ってきました
Lulucom

2021/02/27 23:58

よかったです^ ^ よく状況がわかりました。後からここを見る人の役に立つでしょう。詳しいご説明ありがとうございました。
creative_09

2021/02/28 04:12

ありがとうございます
creative_09

2021/02/28 04:13

バージョンも合わせていないと動作はしなかったです。 参考までに
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.29%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問