javascript PHP 中的实时通知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31354379/
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
Real time notification in PHP
提问by user3201500
I am creating a PHP application, where I want one user make a database entry. It should be reflected to all the users whoever have this app open on their browser will get instant notification that some data has been updated on the database or with whatever data has been inserted.
我正在创建一个 PHP 应用程序,我希望一个用户在其中创建一个数据库条目。它应该反映给所有在浏览器上打开此应用程序的用户,他们将立即收到通知,指出数据库中的某些数据已更新或已插入任何数据。
Is there any way I can get real time notification of data inserted or updated? On all the opened browser without any delay.
有什么方法可以获得插入或更新数据的实时通知?在所有打开的浏览器上没有任何延迟。
We use AJAX for now. But it seems like our application is now working slow due to continues request. Any other way? Which is free.
我们现在使用 AJAX。但似乎我们的应用程序现在由于继续请求而运行缓慢。还有什么办法吗?哪个是免费的。
Thank you!
谢谢!
采纳答案by feeela
You can use web sockets. One existing library example for PHP is Ratchet.
回答by Matt Komarnicki
Take a look at Pusher (https://pusher.com/). It does what you want to achieve and it works like a charm.
看看 Pusher ( https://pusher.com/)。它可以完成您想要实现的目标,并且效果很好。
I don't know what do you use on your server side but even if it isn't Laravel, take a look at Jeffrey's Laracast about implementing real time notifications in Laravel (PHP). https://laracasts.com/lessons/pusher-awesomeness
我不知道你在你的服务器端使用什么,但即使它不是 Laravel,看看杰弗里的 Laracast 关于在 Laravel (PHP) 中实现实时通知。https://laracasts.com/lessons/pusher-awesomeness
Have a fun! When I did it, my app became extremely sexy. Real time notifications, DOM manipulations etc.
玩得开心!当我这样做时,我的应用程序变得非常性感。实时通知、DOM 操作等。