How can the code be modified to prevent loading multiple files simultaneously?

To prevent loading multiple files simultaneously, we can use a flag to track if a file is already being loaded and prevent loading another file until the current one is finished. We can achieve this by setting a boolean variable like $isFileLoading to true when a file is being loaded and set it back to false when the loading is completed.

$isFileLoading = false;

if (!$isFileLoading) {
    $isFileLoading = true;
    
    // Code to load the file
    
    $isFileLoading = false;
}