I am creating an activity feed with PHP for individual and I'm moving on to creating group feeds.
so I have tables of
Table: Group Name 1. Group 1 2. Group 2 3. Group 3
Table: Members 1. Group 1 > Member 1, Member 2, Member 3, Member 4, Member 5 2. Group 2 > Member 3, Member 4, Member 5, Member 5....
Some groups have thousands of members. So when ever I publish a feed, I am doing something like the following.
$result = $this->db->query('SELECT member_id FROM members WHERE group_id = 1');
$members = $result->fetchAll();
foreach ($members as $member) {
$query = $this->db->prepare('INSERT INTO activity_feed (user_id, activity) VALUES(:user_id, :activity);
if ($result = $query->execute(array(
':user_id' => $member['member_id'],
':activity' => $activity
))) {
//do something
$pusher->push(activity) //socket push notification
}
}
Inserting of personal feed only requires one mysql database insert, whereelse As you can see, for group feed the loop gets exponentially larger when the number of members increases.
I was thinking of populating the activity feed using a separate PHP file, and execute it when the activity occurs. How do I call that separate PHP file?
Is there a better idea to solve this problem?
If not I have to go through the loop everytime someone post a message to the group, or upload image to the group and then the PHP file takes along time to execute.