php Laravel 5 中的实时聊天和通知

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29874943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:38:02  来源:igfitidea点击:

Real-time chatting and notifications in laravel 5

phplaravel-5

提问by Hassan Saqib

I need to implement real-time chatting and real-time notifications in my application. What is the best way to do it using laravel-5? Suggest me some good packages or your expert views on them.

我需要在我的应用程序中实现实时聊天和实时通知。使用 laravel-5 的最佳方法是什么?向我推荐一些好的软件包或您对它们的专家意见。

采纳答案by Adnan

For real time chat you need to use asynchronous websockets.

对于实时聊天,您需要使用异步 websockets。

You can try with this library https://github.com/ratchetphp/Ratchet

你可以试试这个库https://github.com/ratchetphp/Ratchet

laravel 5.2 chat

Laravel 5.2 聊天

and this project github.com/assertchris/tutorial-laravel-4-real-time-chat

这个项目 github.com/assertchris/tutorial-laravel-4-real-time-chat

Good library github.com/BrainBoxLabs/brain-socket

不错的库 github.com/BrainBoxLabs/brain-socket

also amazing tutorial with socket IO www.codetutorial.io/laravel-5-and-socket-io-tutorial/

使用 socket IO 也很棒的教程 www.codetutorial.io/laravel-5-and-socket-io-tutorial/

Video example with AJAX and laravel 4 https://www.youtube.com/watch?v=GLDjgbbBvOg

AJAX 和 Laravel 4 的视频示例 https://www.youtube.com/watch?v=GLDjgbbBvOg

回答by leggetter

I recently gave a talk at Symfony Live on "Building Real-Time Symfony Apps. What are your options?". As part of that I covered your options for integrating with real-time frameworks. Although the talk is about Symfony it does also apply to Laravel, or any other PHP Framework.

我最近在 Symfony Live 上做了一个关于“构建实时 Symfony 应用程序。你有什么选择?”的演讲. 作为其中的一部分,我介绍了与实时框架集成的选项。尽管讨论的是 Symfony,但它也适用于 Laravel 或任何其他 PHP 框架。

If you want to go self hosted then Adnan's answercovers a number of good options. With PHP, Ratchet-based solutions are your best bet. However it doesn't offer HTTP fallback so you'll need to implement your own fallback mechanism.

如果您想自行托管,那么Adnan 的回答涵盖了许多不错的选择。使用 PHP,基于 Ratchet 的解决方案是您最好的选择。但是它不提供 HTTP 回退,因此您需要实现自己的回退机制。

PHP + Real-time framework integration

PHP + 实时框架集成

Note: substitute Symfony for Laravel in the above image

注意:将上图中的 Laravel 替换为 Symfony

Since you're integrating with the real-time framework in a loosely coupled way you're not restricted to a PHP-based solution. In that case there are a number of considerations you need to make before choosing what that solution is (again, please see the talkI referenced earlier).

由于您以松散耦合的方式与实时框架集成,因此您不受基于 PHP 的解决方案的限制。在这种情况下,在选择该解决方案之前,您需要考虑许多因素(同样,请参阅我之前引用的演讲)。

You alternative to self-hosted is of course using a hosted service. Laravel 5.1 comes with an Event Broadcasterfor the Pusherhosted real-time service (who I work for).

自托管的替代方案当然是使用托管服务。Laravel 5.1为Pusher托管的实时服务(我为谁工作)提供了一个事件广播器。

Symfony/Laravel + Pusher

Symfony/Laravel + Pusher

Taylor Otwell published a video on Laracasts covering how to go about doing this: https://laracasts.com/lessons/broadcasting-events-in-laravel-5-1

Taylor Otwell 在 Laracasts 上发布了一段视频,介绍了如何做到这一点:https://laracasts.com/lessons/broadcasting-events-in-laravel-5-1

I've also created a set of tutorials on building real-time laravel appsthat walks you through building a notifications feature, activity streams and then authenticating a chat application.

我还创建了一组关于构建实时 Laravel 应用程序教程,引导您构建通知功能、活动流,然后验证聊天应用程序。