Hey, I am working on a fairly expansive project and I want to know the most efficient way to mark items as read / unread by specific users. When a user views an item, it should be marked as read. When a change is made to that item, it should be marked as unread (say, a new comment made). I am wondering how one should store whether a user has read an item or not without taking up massive amounts of data, and of course, as quickly retrievable as possible. The potential problem I see if that one day there will be a thousand items and 100 users will have viewed all of them. That is some serious storage space we're talking about there. I know enough PHP to actually code this myself, of course, so I won't actually need the script. Thanks!
Storage is cheap, relatively. I haven't scoured the backend of vBulletin to see how they do it but it goes something like this they have a "UserItem" table with the following columns * user_id * item_id * timestamp Then users also get to specify in their personal settings * mark_as_read_days Now, when your user logs in you can sweep the UserItem table and delete any rows for the user that have a timestamp more than "mark_as_read_days". Alternatively you could have a cron job to go through each user (or a selection of users based on a last check date). Then when you go to display a list of articles you mark all those with a publish date of more than "mark_as_read_days" ago as read. For all the others you query the "UserItem" array that will have been populated from the "UserItem" table. If the item is in the array then it is read. If its not, then show it as unread. make sense?
Sounds pretty good, actually. I'll see if that will work. The script I am designing is made to be distributed to a large variety of users. How would you recommend I schedule tasks like that? I haven't worked with Cron at all, so I'm unsure if it's usable in this context.
You can put a 1x1 pixel image on your site and when its called it triggers the checks if the last run was more than an hour ago. You can set up a cron job on your server - most hosting packages allow cron jobs There are autocron services around which will ping a script on your site at regular intervals.
Is there a less sloppy way to execute the scheduled file in PHP other than just echoing a 1 pixel image link to the checking script but without slowing down the generation of the page?
Yes, you can just call it from your config file or your footer file. What you want to avoid though, is the browser thinking that the page hasn't fully loaded because there is a background task running and the user getting the impression of a "hang".
So, do you mean that it should be called at the very end of the script, after the entire contents of the page have been echoed?