Forum thread subscription - php

I have written a really simply forum to integrate into a web app as I was struggling to find a lightweight and quick forum which allowed me to use my own authentication methods to decide who was or wasn't a valid users and which fitted into my application theme. Users are asking for the ability to subscribe to threads so they are notified of replies - what is the best way of doing this?
I could create a threads subscriptions table and enter a new row each time someone subscribes - this could involve lots of lookups for busy threads on every post and reply but would be pretty quick on new subscriptions with only one simple insert.
The other option I thought of was to have row per thread and to have a field where I can add (or read from) an array per thread which contains all the subscribed user id's. This strikes me as quicker for reading as there are less database calls (i.e. when a new reply has been made only one database call is needed to get all the user id's) but I think it might be slower for inserts when a new subscriber is added as I would have to find the row for the thread, get the existing array and then add the user id to the existing array.
A final option, very similar to the second one, would be to have a user subscription table where each row is a user id and then have an array of subscribed threads.
Which would be the best way? At the moment my only requirement is to email users on new posts and replies but in the future I may want to expand it to include the ability for users to list their subscribed threads etc like many mainstream forums do.

In my opinion, your two options are good, except for the array thing. You can simply go for a table which contains a unique id for a thread and if a user hit a subscribe button it can be added with his id and the thread id. You can call it, subscription table.
I think array might come handy if a user started subscribing much more threads. It depends on how big your forum is going to be.

Related

General questions about database

I would like to create e-learning platform. So users will have a lot of things to choose (mostly available to view only for them) like:
add note
add movies to favorite
rate the instructor
And few options that auto save for each user like:
unanswered questions
wrong answer questions
movies in progress (user saw only 2 min from 5)
So what database or method I schould use for store that kind of data?
I do not want to use cookies because it needs to be save on user account and not on browser. User need to have that all on every browser or mobile device.
I wondering about json but...if I do so each user I'd will be available to view...so schould I use MySQL?
I would recommend that you build your own data logger, what i mean by this is build yourself a place to store every users data like an eManager if you would like.
Once this has been built you can then assign the eLearning courses using an ID to each of the users profile on your "eManager". Allowing you too keep track of each users progress etc.
The "eManager" could also save the users notes/wrong answers/unanswered questions, you could create surveys with a slider rating to rate the user. Honestly the limit is endless.
You can receive the data in two different ways:
(Personal) Either you can request that your users email you requesting a username and you generate a password and send it out to the user.
(Commercial) You build your eManager to recieve the data from the website which isnt too difficult to do.
It will be a long process and to answer your question in a different view practice SQL/PHP that would be your base make sure you can run more advanced query's and can confidently edit your DB etc.
Anymore questions just let me know, thanks.

Rating and Like System Managment

I'm trying to integrate a rating and like system as part of a package to send to the end user (with unknown progamming skill).
My problem is how to manage the users (registered or not) that have already done an action.At this moment I'm using PHP session to keep stored for a week the information, but this isn't a good solution.Is it a good solution creating 2 tables (one for rating and one for like) to store the information? If I use this solution what's the most useful and "correct" information to retrieve if the user is not registered? And is it user-friendly?I have thought to store: username and the ip
I would extend the members's table with at least two new columns, likes and rating or create a new table (as you said) including the memberID with a reference(and an index) to store and select the data. I believe it's the best way. Unfortunately, in this case non-members cannot press like or rate, but it is a good reason for one to register. –

PHP/MYSQL help for giving notifications to all users(followers) even millions of them

I want to make a system in PHP/MYSQL through which users of a site can follow/unfollow other users of the same site and when a user do some activity then that user's all followers should get a notification.
I know that I can create a seperate db tables called notifications and insert row in it for each user who needs to be notified separably like Facebook did, but i will not restrict users (i.e. on Facebook you cannot have more then 5000 friends), on my site users can follow any amount of users they wish, and if some user have 1 million followers then on my server his each and every activity will let my server down.
So how to accomplish this task, what kind of design do I need to use for my Mysql database, in what way do I need to call those rows so that i can send notifications to all followers of the user and the server also never let down.
The follower pulls the notifications from the users he follows. That way, a notification is a single row in a table. The rational is, that while I might have millions of followers, the number of people that I follow is quite small (probably less than 1000).
Also: think about a caching strategy.
Use a combination of your suggestion and the answer and comments from Oswald.
The author creates an update, which will then add records to the notifications table(s). If the author has 10,000 followers, then there are 10,000 entries. This will become quite large, and optimization, caching, etc... will need to be used.
The follower then connects at some interval (via a client similar to Facebook web or hand held) and pulls their notifications. In this case, I get notifications from my last visit or all my authors. Again, this may be 10,000 rows as you indicated, but with better keys, the retrieval will be quick, since you get notifications for the follower only (their ID). Once received, delete the pending notifications.
The second alternative would be to modify the notifications to simply have an entry for the author, and the post, and a date. The follower connects, queries for new postings since his last search, and then filter them by author. Try to remove as many records as possible in the first query, then attempt the filter as a second query or cached reference search. Do not try to link both queries as you will kill the database server. Using keys/indexes to get the smallest set first.
If the follower has a few authors, query for author updates first, then after the date. Otherwise, search after the date then by authors.

Game Lobby in PHP/MySQL

I'm creating a mobile game on various mobile platforms and have decided to use PHP/MySQL as the back end and communicate with this via JSON. (The game will be text based).
I'm lacking on idea's on how to implement this, the sort of logic i'm after is as follows;
User will need to register an account
User will enter the game lobby looking for an open slot
If there is a suitable game ready and waiting (not full and waiting for new players) then join
If not create a new game and await players
I was thinking of having 20 players for each game and only allowing the game to start when there's 3 or more players waiting. When there's 3 or more players waiting there would be a count down of say 60 seconds until the game began.
Now i know some of this might need to be done on the client side. I'm struggling on where to start!! So any idea's, code samples or links to reading material that may help would be very much appreciated.
thanks!
Based on comments, I'm guessing you're looking for some ideas on database schema, like Brad Christie suggests. So I'm going to start with that.
First, you'll need a table for the players. I'm guessing you already have one of those, but you'll probably want to include a field for the game ID that they're in.
Next, you'll need a table for the games. This is where you store information on the game itself, including whether it's active. To get the player count, you simply query the list of players with that game's ID. You could also keep track of player count and update it whenever the player leaves or joins the game, depending on a few factors.
Now, the game lobby itself. The exact method here really depends on how you want it to function. You can either use AJAX to keep a list of currently active games up to date (and set up some sort of chat system to let players talk while waiting), or you can use the game lobby as routing page. If you go the latter route, then query the active games, automatically dump the player into one that meets your criteria, then send the user to the 'main game page'.
Hopefully this will give you a solid outline on how to start. I'm afraid I can't help you much more unless I know more about your requirements.
For register a user you simply need a form and save that form in your database. When the user logs in the you query the database matching the password and user name.

Integrating a "watchlist" feature in php (symfony)

I was looking for input about integrating a feature that:
*When a new article is added, search for users having a watchlist taht match the article categorie.
*Send them an email with the new article.
I am kind of worried it will slow the application to browse the whole watchlist table everytime a new article popup.
What would be the best way to integrate that?
Is doing a cron job that check every hours new article and compare them to watchlists a good idea? One email per day?
Thanks!
If I were doing this, I would only worry if (numberOfwatchlists) * (newArticlesPerMinute) is a very large number.
As for not spaming emails, I think a once a day check would be good.

Categories