Suppose there is an engineering PhD student who is unsure whether to join academia or the industry after his PhD. He does not want to take chances and applies for internship positions during the course of his PhD. Here is a dilemma: the internship is certain to eat into vital amount of time he could otherwise spend thinking about his research problem. OTOH, when he is not fully into research, he is unlikely to get attractive research-based internship positions.
How should a PhD candidate time his internship in a way that it does not affect his research and is also a very valuable experience on his PhD resume?
Although the answers above are great, I would like to share a different perspective mainly because I disagree with necessarily waiting until the 3rd year of your Phd. In a lot of internships, you're exposed to new areas or new perspectives in the same area which can affect your current interests. Although school is good and working on research is even better, still, you learn work mainly at work.