Keep a file for each logged in user that is updated each time a new message arrives (maybe with the line numbers of the messages?). Then all the client has to do is check if the updated time has changed since the last access, and if it has, only THEN access the database. The file can be deleted if a user logs out, and also deleted if an expiration time is reached (let's say if the user hasn't logged in for 24 hours), thus keeping the number of files relatively small, or at least smaller than your total number of users.
Having the client listen for messages instead of checking for them would of course be the more elegant solution, but that method requires a good deal more complicated programming and most likely comes with problems of its own.
A third possibility is to vary the access speed so you get 1 second accesses within x minutes of your last message (in or out), then a gradually slower access speed down to eventually 30-60 second accesses. This should significantly cut database calls without hurting your messaging system much or requiring complicated rewrites.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.