您是否曾經想過使用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.