tag:crieit.net,2005:https://crieit.net/tags/Pusher/feed 「Pusher」の記事 - Crieit Crieitでタグ「Pusher」に投稿された最近の記事 2020-10-19T18:05:31+09:00 https://crieit.net/tags/Pusher/feed tag:crieit.net,2005:PublicArticle/16151 2020-10-19T18:05:31+09:00 2020-10-19T18:05:31+09:00 https://crieit.net/posts/Laravel-Pusher-The-data-content-of-this-event-exceeds-the-allowed-maximum 【Laravel+Pusher】The data content of this event exceeds the allowed maximum のエラーが出た時 <p><a target="_blank" rel="nofollow noopener" href="https://pusher.com/docs/channels/server_api/http-api#publishing-events">https://pusher.com/docs/channels/server_api/http-api#publishing-events</a></p> <p>↑にも書いてあるが、<br /> The data content (POST body) of events must be smaller than 10kB.<br /> (イベントのデータコンテンツ(POST本文)は10kB未満である必要があります。)</p> <p>とのことなので、<br /> イベントに何でもかんでもぶち込むとエラーになるっぽい。</p> <h1 id="解決策"><a href="#%E8%A7%A3%E6%B1%BA%E7%AD%96">解決策</a></h1> <pre><code class="php">$event = [ "eventType" => 1, "id" => 1, "content" => [...] // ←ここのサイズが大きかった ]; event(new PusherEvent($event)); </code></pre> <p>↑これをvueで受け取って、</p> <pre><code class="js">this.content = event.content </code></pre> <p>のようにしていたのを、</p> <pre><code class="php">$event = [ "eventType" => 1, "id" => 1, ]; event(new PusherEvent($event)); </code></pre> <p>イベントタイプとデータのidのみ渡すように修正</p> <pre><code class="js">async getContent(id) { // ajaxでデータ取得 }, ... ver content = await getContent(event.id); this.content = content </code></pre> <p>ajaxでデータを取得し、それを反映</p> <p>という風に直したら解決。</p> <p>もちろん仕様によってはある程度制御をしなければ、<br /> ログインしているユーザー人数だけgetContent()が呼ばれてまた別のエラーになるので、<br /> そこは適宜対応が必要。</p> みみみみみ