In terms of scalability, what are some alternative approaches to tracking read threads in a PHP forum to avoid creating a large array?

When tracking read threads in a PHP forum, storing all read threads in a large array can become inefficient and lead to scalability issues as the number of threads grows. One alternative approach is to store read threads in a database table and query this table when checking for read threads.

// Assuming you have a database connection established

// Function to mark a thread as read for a specific user
function markThreadAsRead($userId, $threadId) {
    // Insert a record into the read_threads table
    $query = "INSERT INTO read_threads (user_id, thread_id) VALUES ($userId, $threadId)";
    mysqli_query($connection, $query);
}

// Function to check if a thread has been read by a specific user
function isThreadRead($userId, $threadId) {
    // Query the read_threads table to check if the thread has been marked as read
    $query = "SELECT * FROM read_threads WHERE user_id = $userId AND thread_id = $threadId";
    $result = mysqli_query($connection, $query);
    
    // If a record is found, the thread has been read
    return mysqli_num_rows($result) > 0;
}