Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP get request blocking

Tags:

php

mysql

caching

Essentially I want to grab the newest results once they are updated as fast as I can, so I don't think it will be efficient to spam the PHP/MySQL script with AJAX constantly to check for newer results (like every 3 seconds once per visitor).

If I will setup an automatic call to a script that will cache the results every time they are updated and then hold the PHP request of every visitor until the value of the cache stored within the file doesn't meet the posted "last updated" value from the visitor, would it be a worthwhile approach?

Thanks for your assistance guys.

like image 840
user2372936 Avatar asked Jan 27 '26 04:01

user2372936


1 Answers

The best solution will be to use WebSocket / NodeJS + Socket.IO, it can open a socket and you can do real-time applications with really small bandwidth and load ( similar to facebook chat for example. They don't do requests every X second, but the information in the chat is updated realtime ). Check it out! It is worth it.

The problem with the NodeJS is that most of the web hosts won't allow you to run third-party application. You'll need a VPS or any other NodeJS host.

You can find more information on http://nodejs.org/

Now on topic: Even if doing "real-time" application only with PHP is bad practice, the best solution in my opinion should be to make requests for JSON data for example. The solution you mentioned is nice, but it will do a additional request if it find a change. The JSON data is small and I think the bandwidth difference will be really small.

More information about JSON here: http://php.net/manual/en/book.json.php

like image 52
Deepsy Avatar answered Jan 28 '26 17:01

Deepsy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!