The foreach loop you posted would not crash the server, so I can only assume that the actual foreach loop that you're executing is doing something different from what you posted. We can't help you troubleshoot code that you haven't shown us.

We also need details on what you mean when you say the server crashed.

BTW, it's almost always better to use a while loop instead of slurping the file into an array and then loop over that array.