forece refresh client page from server side [closed]

拈花ヽ惹草 提交于 2019-12-01 01:18:26

Use Web Sockets. You can use either PHP Sockets with this or this

I think php Sockets would require you to have a PHP version of 5.3 or above.

If you don't have PHP v5.3 or above you can use Node JS with Socket.io

Long Pooling is also one of the option, but that won't be a good solution considering the number of requests your server would be getting. Also the user's bandwidth usage will go high.

You can get the behavior in two ways:

WebSockets - If all your clients connect via web sockets, you have a direct connection between the client and the server. You'll need to get creative with timing, but you can certainly send a command at any time requiring a refresh. This requires that you implement web sockets in PHP http://socketo.me/ and JavaScript.

Polling - You can set up the client to send an AJAX request every x seconds. The server responds with a bool value which the AJAX success handler uses to determine whether it should refresh the page.

If you want to refresh the page at a certain interval, include this in your <head>:

<meta http-equiv="refresh" content="5">

Change "5" to whatever number of seconds you prefer.

If you want to refresh only when things have changed, you'd need to get some Javascript involved on the client - e.g. an Ajax request to a URL that asks if there's new data since page load, and refreshes if necessary.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!