来自Laravel的实时更新前端数据 [英] Real time update front end data comming from laravel

查看:520
本文介绍了来自Laravel的实时更新前端数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原始问题 我是PHP Web开发和Laravel的新手,正在寻找一种实时更新前端数据的好方法.我正在开发一个简单的基于网络的游戏,可以与多个玩家一起玩.当玩家转牌时,所有玩家前端中的数据都需要更新.

Orriginal question I'm relatively new to PHP web development and Laravel and looking for a good way to update my front end data real time. I'm developing a simple web based game what can be played with multiple players. When a player did his turn, the data in all players front end need to be updated.

我知道有两种方法可以做到这一点

I know there are 2 ways to do this

  1. Websocket(s): Laravel默认不支持websockets,这意味着我需要使用套接字IO之类的第三方服务.由于我只想在常规"网络托管上运行我的应用程序,因此这不是一种选择.
  2. 推送消息:我还可以将推送消息与Pusher或firebase之类的服务一起使用,但使用免费帐户时此选项受到限制,或者我需要多于x个资源后才需要付款.这不是我想要的.
  1. Websocket(s): Laravel does not support websockets by default what means i need to use a third party service like socket IO. As i just want to run my application on a "normal" web hosting, this is not an option.
  2. push messages:I can also use push message with a service like Pusher or firebase but this option has restrictions when using a free account OR i need to pay after i need more than x resources. This is not what i prefer.

是否可以在不使用第三方服务或在服务器上安装第三方应用程序的情况下更新前端数据?

Is there a way to update the front end data without using 3rd party services OR installing a 3rd party application on the server?

与上一个问题分开,我很好奇推送消息(以及最终建议的解决方案)是否也适用于移动浏览器.

Serparated from the previous question, i'm curious if push messages (and the eventually suggested solution) works also for mobile browsers.

问题更新: 在发表Yeeooow的评论后,我注意到我需要提出不同的问题.也许我需要多解释一下我的问题",并为此寻求解决方案.

Question update: After the comment of Yeeooow i noticed that i needed to ask the question different. Maybe i need to explain my "problem" a bit more and ask for the solution for this.

在我的游戏中,玩家决定回合结束的时间,并且可以与其他玩家交易一张牌.在这两种情况下,都需要为所有玩家更新数据.我将Vue用于前端,将Laravel用于后端.满足我的需求的最佳实践是什么?

In my game a player decides when his turn ends and he can trade a card with other players. In both cases the data need to be updated for all players. I use Vue for the front end and Laravel for backend. What is the best practice to achieve my needs?

推荐答案

您可以将Websocket与laravel一起使用,例如 Ratchet 我曾经在laravel上使用过它,但是您不能在共享主机上使用它,因为您需要导入ZMQ并打开一些端口,并且在共享主机上不可用,它在VPS或专用主机上可用

you can use websockets with laravel like Ratchet i had used it with laravel, but you can't use it on shared hosting because you need to import ZMQ and open some ports and that's is not available on shared hosting it is available on VPS or dedicated hosting

这篇关于来自Laravel的实时更新前端数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆