简体   繁体   English

laravel实时应用(如gmail和Github)的要求

[英]Requirements for laravel real-time apps like gmail and Github

For implementing a real-time application in Laravel like Gmail or Github , in which all things (such as opening new page, sending mail, inbox, submit forms and etc) occur in one page, I did a lot of research and found that I should use Laravel Pusher package. 为了在Laravel中实现实时应用程序(例如GmailGithub) ,其中所有事情(例如打开新页面,发送邮件,收件箱,提交表单等)都在一个页面中进行,我做了很多研究,发现我应该使用Laravel Pusher软件包。 But I think it is not free for large projects. 但是我认为大型项目不是免费的。

Also I read https://www.codetutorial.io/laravel-5-and-socket-io-tutorial/ article (and many other articles) that uses redis with NodeJs . 此外,我读https://www.codetutorial.io/laravel-5-and-socket-io-tutorial/使用Redis的与文章的NodeJS(和许多其他物品)。

Regardless of Laravel Pusher , my Question is what is best and usual way to implement real-time apps via Laravel ? 无论使用Laravel Pusher ,我的问题是通过Laravel实施实时应用程序的最佳和常用方法是什么?

I am using Laravel 5.2 我正在使用Laravel 5.2

What you are calling real-time apps are really called single page applications or SPAs. 您所说的实时应用程序实际上称为单页应用程序或SPA。 Real-time applications are things such as software for airplanes, trains and stock exchanges. 实时应用是诸如飞机,火车和证券交易所的软件之类的东西。

If you want to create SPA you don't necessarily need pushing services. 如果要创建SPA,则不一定需要推送服务。 I would suggest you to take a look at these front-end projects: 我建议您看一下这些前端项目:

  • Angular js 角js
  • React js React JS
  • Vue js Vue js

As @gurghet pointed out, there is a difference between a SPA and a realtime application. 正如@gurghet指出的那样,SPA和实时应用程序之间是有区别的。 Gmail is indeed a real time application instead of a SPA. Gmail确实是实时应用程序,而不是SPA。

API Comes first: API优先:

If you are looking into creating REALTIME Applications, then first of all you have to create an API (REST/SOAP). 如果要创建REALTIME应用程序,则首先必须创建一个API(REST / SOAP)。 Laravel and Lumen both provide an excellent code base to start your api in no time. Laravel和Lumen都提供了出色的代码库,可以立即启动您的api。

Choosing the right JS framework: 选择正确的JS框架:

Once you have an API, you will need a JS framework. 一旦有了API,就需要一个JS框架。 When it comes to REAL TIME applications, there are just a hand full of frameworks that will give you true flexibility. 当涉及到实时应用程序时,只有一堆充满框架的框架可以为您带来真正的灵活性。 Angular being on the top, followed by REACT, BACKBONE and meteor. 角度位于顶部,其次是REACT,BACKBONE和流星。

Angular has lots of fan following/community, so it should be the appropriate choice. Angular有很多粉丝追随者/社区,因此应该是适当的选择。

The Perfect PHP Stack: Laravel + Angular stack is great. 完美的PHP堆栈: Laravel + Angular堆栈很棒。 Laravel is very flexible so you can do almost any kind of server side scripting with it. Laravel非常灵活,因此您可以使用它执行几乎所有类型的服务器端脚本。 It also keeps on inspiring you to write cleaner code each time. 它还会不断激励您每次编写更简洁的代码。 While angular is very good with 2 way bindings. 虽然有2向绑定的角度非常好。 Which means that when you pass the same data to a view in different places, angular keeps track of all the changes made to the data. 这意味着当您将相同数据传递到不同位置的视图时,angular会跟踪对数据所做的所有更改。 It also has features like PROMISES, where angular doesn't wait to get real data from the db, instead it just assumes that the data should have been updated to the db and just shows you the changes (the ones that it keeps track of) in real time. 它还具有诸如PROMISES之类的功能,其中angular不等待从数据库中获取真实数据,而是仅假定数据应该已更新到db,并仅向您显示更改(它跟踪的更改)。实时。

The Authentication: The most frustrating part of the whole process, is securely authenticating users ie passing data from angular to laravel. 认证:整个过程中最令人沮丧的部分是安全地认证用户,即将数据从有角度的传递到laravel。 You will have to use OAUTH or JWT for authenticating users. 您将必须使用OAUTH或JWT对用户进行身份验证。 Although both have been around for a while, but you wont find any good code/guides regarding authentication. 尽管两者已经存在了一段时间,但是您不会找到任何有关身份验证的良好代码/指南。 I have spent lot of time here, but you can always purchase some bootstrapped / properly configured projects on codecanyon. 我在这里花了很多时间,但是您始终可以在codecanyon上购买一些自举/正确配置的项目。

Sockets are the key: No Real Time system can exist without sockets, you cant just keep hitting the db on regular intervals to check for updated values. 套接字是关键:没有套接字就不能存在实时系统,您不能仅以固定的时间间隔访问数据库以检查更新的值。 Here sockets save the day by informing the system that updates are available, upon which you can grab the updated values from db. 在这里,套接字通过通知系统有可用的更新来节省一天的时间,然后您可以从数据库中获取更新的值。

Now a days services like pusher, have solved most of the problems and laravel also comes with a built-in api-client for pusher. 如今,诸如pusher之类的服务已经解决了大多数问题,并且laravel还带有内置的用于pusher的api客户端。 But you are always free to use opensource softwares to create your own socketing system eg. 但是,您始终可以自由使用开源软件来创建自己的套接字系统,例如。 socket.io . socket.io

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM