calling php function
Moderator: General Moderators
calling php function
OK, got a couple of questions.
I'm developing an app that will query a database and load a default page. I then want to periodically (every minute) be able to check if there have been any updates to the database...WITHOUT refreshing the page.
Is this possible? Can you call a php function from javascript that checks the DB and returns true if any updates have been made?
Thanks for any replies.
I'm developing an app that will query a database and load a default page. I then want to periodically (every minute) be able to check if there have been any updates to the database...WITHOUT refreshing the page.
Is this possible? Can you call a php function from javascript that checks the DB and returns true if any updates have been made?
Thanks for any replies.
Last edited by codebuzz on Wed Mar 31, 2004 5:17 pm, edited 1 time in total.
well, the javascript can control how often the other PHP page is called.
I don't even know if it is possible....I should just refresh the page, but I'd rather not have the database take a hit like that.
Lets say this app is for about 200 people and if 100 are on and it refreshes every minute...that's a lot hits on the DB.
Any one got suggestions of how I could get around making all these calls to the DB unless there has been an update??
Thanks
I don't even know if it is possible....I should just refresh the page, but I'd rather not have the database take a hit like that.
Lets say this app is for about 200 people and if 100 are on and it refreshes every minute...that's a lot hits on the DB.
Any one got suggestions of how I could get around making all these calls to the DB unless there has been an update??
Thanks
Last edited by codebuzz on Thu Apr 01, 2004 9:14 am, edited 1 time in total.
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
wether or not you refresh the page you are still going to have to hit the DB to see if its been updated! If you are trying to ease up on your server i could see why you wouldnt want to reload, but if you are trying to ease up on the DB, it doesnt matter, just relaod, but have a file on your machine that something is written to whenever someone does something in the Dbase then just check that file and if it indicates that something has changed then hit the dbase and set the file back to no nochanged state. This still may hamper performance, however, I don't know if it would be more resource intensive to hit the Dbase or to read and write a file all the time.
That is an excellent idea...Thank you. I think I can use a combo of your idea and the iFrame...magicrobotmonkey wrote:wether or not you refresh the page you are still going to have to hit the DB to see if its been updated! If you are trying to ease up on your server i could see why you wouldnt want to reload, but if you are trying to ease up on the DB, it doesnt matter, just relaod, but have a file on your machine that something is written to whenever someone does something in the Dbase then just check that file and if it indicates that something has changed then hit the dbase and set the file back to no nochanged state. This still may hamper performance, however, I don't know if it would be more resource intensive to hit the Dbase or to read and write a file all the time.
I can have a file that holds a variable with a timestamp value on the server. When a change is made to the DB, it updates the timestamp in that file.... When the user is viewing the page, there is an iFrame that refreshed a php script every minute or so. Every time it loads, it pulls the current timestamp from the file. When it refreshes, it checks the files timestamp and if it is newer, is makes the parent page refresh!
Comments, suggestions please...................Keep em coming and thanks.
PHP/MySQL - Problem tracking apppatrikG wrote:depends on the database you're using, you could set it so that the update-event is triggered whenever the database is updated.
Not possible in mySQL, though. AFAIK should be possible in SQLite and Oracle, but have no experience with it.
What kind of application are you coding?
Last edited by codebuzz on Thu Apr 01, 2004 9:13 am, edited 1 time in total.
You could use MySQL's Binary logging feature.
See http://www.mysql.com/doc/en/Binary_log.html
"The binary log, like the old update log, only logs statements that really update data. So an UPDATE or a DELETE with a WHERE that finds no rows is not written to the log. It even skips UPDATE statements that set a column to the value it already has."
So by checking the size/date of the binary log file you know if 'somethings changed'
See http://www.mysql.com/doc/en/Binary_log.html
"The binary log, like the old update log, only logs statements that really update data. So an UPDATE or a DELETE with a WHERE that finds no rows is not written to the log. It even skips UPDATE statements that set a column to the value it already has."
So by checking the size/date of the binary log file you know if 'somethings changed'