Continuous monitoring database with PHP

I have a big problem that I can not fix.
I have a php script (echo $variable1)
Now I wish every 2-3 seconds is checked the database, and the PHP code variables are updated.
It’s possible? How?
Thank you so much!

ps: sorry for my english, but i’m italian

Hi Cristian_Livella welcome to the forum

I’m not 100% clear what you’re after, but seeing “echo” suggests you want a page to update it’s content based on the current database value.

PHP can do “stuff” then output HTML. But once it is done outputting the page the only way to get fresh content is either to reload the page or use JavaScript.

Every 2-3 seconds seems a bit too often to be doing a full page reload.

So if this is what you are describing - i.e. updating a single variable value in a page - I suggest you look at finding a JavaScript method.

If this isn’t what you are describing, please try to explain again.

Thanks for the reply.
I too thought Javascript, but being on the client side can not communicate with the database …

other than by calling a script on the server to do the database access for it.

Also either JavaScript or a cron job is the only way to run PHP to check the database for frequently than just when someone requests to load the page and a cron job has no way to echo anything in a browser leaving JavaScript as the only way to get regular updates from the database while the person is still viewing the page.

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.