How can developers avoid server crashes when running large loops in PHP?

Developers can avoid server crashes when running large loops in PHP by implementing a timeout mechanism that breaks out of the loop after a certain amount of time. This prevents the script from running indefinitely and causing the server to crash. One way to achieve this is by using the `set_time_limit()` function to set a maximum execution time for the script.

set_time_limit(30); // Set maximum execution time to 30 seconds

// Large loop that may potentially cause server crashes
for ($i = 0; $i < 1000000; $i++) {
    // Code inside the loop
}