What are some best practices for closing forum threads on PHP forums to maintain organization and prevent spam?

To maintain organization and prevent spam on PHP forums, it is best practice to close forum threads after a certain period of inactivity or after a resolution has been reached. This helps to keep the forum tidy and prevents unnecessary clutter. One way to implement this is by adding a function that checks the last activity timestamp of a thread and automatically closes it if it exceeds a certain threshold.

// Check last activity timestamp and close thread if inactive for more than 30 days
function closeInactiveThreads($thread_id) {
    $last_activity = get_last_activity_timestamp($thread_id);
    $current_time = time();

    if (($current_time - $last_activity) > (30 * 24 * 60 * 60)) {
        close_thread($thread_id);
    }
}

// Function to get last activity timestamp of a thread
function get_last_activity_timestamp($thread_id) {
    // Query database to get last activity timestamp
    $last_activity = // query to get last activity timestamp

    return $last_activity;
}

// Function to close a thread
function close_thread($thread_id) {
    // Update database to mark thread as closed
    // Example: UPDATE threads SET status = 'closed' WHERE id = $thread_id
}