您是否曾经想过使用Websockets而不使用Pusher之类的外部服务?在本视频中,我将向您展示如何最终在没有任何外部服务的情况下利用Laravel中的websockets功能。我们将使用Laravel Echo来处理前端的套接字,并使用Laravel事件来触发服务器端的事件。
今天我们将用来操作Websocket的方法是一个称为laravel-websockets的软件包。该软件包实际上将一个低级Web套接字服务器Ratchet的实例导入到我们的Laravel项目中,从而使我们能够将Websocket服务器作为现有Laravel应用程序的一部分进行托管。这很方便,因为所有内容都是在一个Laravel应用程序中包含的。
您可以在需要Web套接字的Laravel应用程序中运行此Web套接字服务器,也可以选择托管一个独立的应用程序,该应用程序为您自己的自托管Websocket平台运行此程序包。就像其他流行的websocket服务一样,它可以支持多个客户端。
这个软件包扩展性很好,仅使用一个简单的512Mb ram VPS服务器就可以维护超过15,000个并发连接,该服务器通常每月花费约5美元。
▼▼▼链接▼▼▼
下一步(可选):配置Laravel-Websockets-了解设置:https://youtu.be/V4Nqog5eXuQ
在YouTube上的“我的完整(免费)”课程中详细了解Websocket:https://www.youtube.com/playlist?list = PLwAKR305CRO9rlj-U9oOi4m2sQaWN6XA8
Laravel-Websockets软件包:https://github.com/beyondcode/laravel-websockets
Laravel-Websockets文档:https://docs.beyondco.de/laravel-websockets/
安装片段:https://docs.beyondco.de/laravel-websockets/1.0/getting-started/installation.html
该软件包可扩展吗?:https://docs.beyondco.de/laravel-websockets/1.0/faq/scaling.html
▼▼▼代码片段▼▼▼
这是一个简单的设置教程,因此没有提供GitHub存储库。
在现有的Laravel应用中安装
1)通过作曲家安装:
作曲家需要beyondcode / laravel-websockets
2)发布迁移文件:
php artisan vendor:publish –provider =“ BeyondCode LaravelWebSockets WebSocketsServiceProvider” –tag =“ migrations”
3)发布配置文件:
php artisan供应商:发布–provider =“ BeyondCode LaravelWebSockets WebSocketsServiceProvider” –tag =“ config”
4)运行迁移:
PHP的工匠迁移
要启动Web套接字服务器,请运行:
PHP的工匠websockets:服务
====跟我来====
订阅新版本!
订阅DevMarketer Insider
https://confirmsubscription.com/h/d/5EDC91CF554832D1
Twitter-http://twitter.com/_jacurtis
(问我问题!)
====问题? ====
在下面发表评论,我或其他人可以为您提供帮助。
对于快速问题,您可能还想在Twitter上问我,我几乎立即做出回应。
给我发电子邮件[email protected]
感谢您的支持! 。
Why are you wearing a jacket inside? Sorry had to ask.
if i was to set up a laravel cron job to run websockets:serve once per hour to make sure its running will this cause issues?
Quick question. Just out of curiosity, what font do you use in your ide?
wow i can't thank you enough!!
but i have a question…
i have a website (not a laravel app) and it connects to laravel eloquent to fetch data and insert using ajax
how can i subscribe to laravel websockets channel and listen to it using js?
thank you so much man
I'm trying to bind port 80 to 6001 on nginx, but didnt get it, so that I do not need to pass :6001 on url. Does any one know how to do it ?
Thanks man! I'll stop paying pusher right now!
Dude what's the name of the font you're using?
Could you please help me with running this websocket on linux live server. I have put my all efforts into this but nothing came useful. Plese make a seperate video for running queue and websocket using supervisor. It will be really appreciated.
what is the theme that you use ?
Thankful for your effort
How do we host it elsewhere? / App on one server and websocket on another
Hi, did everything as in tutorial, set up in .env APP_URL=http://websockets.test , then artisan phph serve , php artisan websockets:serve – but in browser on address http://websockets.test I get only 'page can't be found' . Is it something missing? Do I do something wrong?
im getting an error, Echo is undefined
i am getting error blocked by CORS policy in production?? can someone help me?
Can you please share the font name that you are using in editor Thanks
Can I use native javascript as a client with laravel web sockets instead of Laravel-Echo?
Hey DevMarketer
How I can use ws protocol with Self-Host Web socket server. I don't want to use http or https. Please guide
Can we have a tutorial that uses redis as the driver for broadcast. Also i had to face difficulties inplementing your approach on laravel 5.8 – 6.x
Hey DevMarketer! Great video, just one question:
Can I use this to couple with a separate Nuxt application on a different domain? Can't seem to find anything about it?
I have my backend Laravel API working fine with this, just would also like to post to my front-end Nuxt application as well…
Nice tutorial… Am finding it hard getting this to work on forge with https.
Very Well Explained 🙂
Hey ended up with this error any help would be great. "Argument 2 passed to BeyondCodeLaravelWebSocketsAppsApp::__construct() must be of the type string, null given
2 questions:
-How to set this up with let's encrypt? I cannot get it to work at all.
-If let's encrypt changes the SSL every 30 days, how to keep the paths working?
is it used pusher ?
have any limitation of connection?
how to configure this package on a remote server
Is there an alternative to Valet for Windows users? I would like to bring statistics to my project.