Click data on a page without checking it periodically?

Is there any way you can transfer data to a page, and not periodically check it?

Obviously, you can periodically check it with ajax, but is there a way to force the page to reload when running a php script?

Theoretically, you can improve the speed of an ajax request by having a table only for when it is supposed to execute the ajax function (update the value in the table when the ajax function should retrieve new data from the database), but this still requires a significant amount of memory and mysql connection, and also some time to wait until the request is executed, even if there is no update / you do not want to execute the ajax function, which retrieves database data.

Is there a way to make this even more effective than querying the database and checking the table in which the data is stored "if updated", or telling the ajax functions to execute from another page?

I assume node.js or HTML5 webSocket could also be a viable solution?

Or could you store the โ€œupdatedโ€ data in a text file? Any suggestions are welcome.

+6
source share
4 answers

Basically you are talking about notifying the client (i.e. browser) about events on the server side . It really comes down to two things:

  • Which web server are you using? (are you limited to a particular language?)
  • What browsers do you need for support?

Your best bet is to use WebSockets to do the job, something other than using web sockets is a hack. However, many โ€œhacksโ€ work very well, I suggest you try Comet or AJAX long-polling .

There is a project called Atmosphere (and many others) that provide you with a solution suitable for the web server you are using, and then automatically selects the best option depending on the user's browser.

If you are not limited to browsers and can choose your own web stack, I suggest using SocketIO + nodejs . This is just my preference right now, WebSockets is still in it, and everything will be interesting as soon as it starts to develop more. Sometimes my application is not suitable for nodejs, so I just unload the data operation into it.

Good luck.

+2
source

Another possibility, if you can store data in a simple format in a file, you update the data file and use the web server to check its timestamp.

The browser can then interrogate by making HEAD requests that will check the file update time to see if it needs an updated copy.

This avoids calling the database for anything that does not change data, but by saving copies of important resources in the file system. This can be a good compromise, though, if you can do this for active data and discard it after a while. You will need to make sure that you manage to change this on any call that updates the data.

It shares the risks of synchronizing any systems with multiple copies of the same data, but it may be worth exploring whether it is worthwhile to increase risk sensitivity.

+2
source

Once there was a technology called a โ€œpush serverโ€ that supported the web server process that was sitting there, waiting for your script to exit and redirecting it to the client when it appeared. It was the hot new technology of 1995, and although you may still be able to do it, no one does because it is a bizarrely awful idea.

So yes, you can, but when you get there, most likely you will not wish it.

+1
source

Well, you can (or will) with HTML5 sockets.

This page provides excellent information about this technology:

http://www.html5rocks.com/en/tutorials/websockets/basics/

0
source

Source: https://habr.com/ru/post/920054/


All Articles