Flames Posted December 12, 2008 Share Posted December 12, 2008 I want to know if its possible to make a script that refreshes a div but only when there has been an update to MySQL. What im actually trying to do is a chat system which will refresh if somebody posts a new message. Guides and stuff would be nice Quote Link to comment Share on other sites More sharing options...
corbin Posted December 12, 2008 Share Posted December 12, 2008 You will have to make the web page ask the server if there is new content over and over again. It's not [reasonably] possible for a web server to tell a web page that there is new content. Quote Link to comment Share on other sites More sharing options...
Flames Posted December 12, 2008 Author Share Posted December 12, 2008 and how does the server know there is new content do i just keep auto-refreshing the query every second? Quote Link to comment Share on other sites More sharing options...
Mchl Posted December 12, 2008 Share Posted December 12, 2008 For real time chat's use some other technology, like Java or Flash With JavaScript and PHP you might recheck for changes every 10 seconds or so. Also, it might be good idea, to have a file on server, that would be rewritten each time a message is entered into database. Then you just have to compare the time when it was changed to the time of last displayed message to know if there are new messages. Quote Link to comment Share on other sites More sharing options...
corbin Posted December 13, 2008 Share Posted December 13, 2008 For real time chat's use some other technology, like Java or Flash With JavaScript and PHP you might recheck for changes every 10 seconds or so. Also, it might be good idea, to have a file on server, that would be rewritten each time a message is entered into database. Then you just have to compare the time when it was changed to the time of last displayed message to know if there are new messages. I would just do SELECT * FROM posts WHERE time > last time checked; Or compare post IDs or what ever. The file management would get to be a pain. Locking would come into play too, although under linux it should work fine. @OP As Mchl said, you could use Java or Flash to give the user actual real time content. Both Java and Flash can open sockets, so you could just write a mini server on your server (lol) to handle the stuff. Problem with that though, is that you must always have a script running. Some webhosts aren't real keen on that, especially if you screw up and it hogs resources. If you write a socket script in PHP with an infinite loop, make sure to use usleep or it will use 100% CPU. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.