How can PHP and MySQL on the same server affect network traffic when retrieving data?

When PHP and MySQL are on the same server, retrieving data can cause an increase in network traffic as the data is transferred between the PHP application and the MySQL database. To reduce network traffic, you can optimize your queries, use caching mechanisms, and minimize unnecessary data transfer.

// Example of optimizing query to reduce network traffic
$query = "SELECT * FROM users WHERE status = 'active'";
$result = mysqli_query($connection, $query);

// Process the result set
while ($row = mysqli_fetch_assoc($result)) {
    // Output or process data
}