Contour integration is a great tool for definite integrals, especially of the following type: $$\int_{-\infty}^\infty \frac{f(x)dx}{P(x)}$$ where $P(x)$ is a polynomial with no zeroes on the real axis (as far as I remember) and $f(x)$ is some appropriate regular function, which vanishes fast enough in the upper half-plane of $\mathbb{C}$. I'm not going to go into details here and refer everyone to a textbook definition.
Contour integration seems like magic to be, and I'm sure to most of the regular people who use it either during their education or for various applications like physics. It's simple for me to see how it works in the complex plane, but not how it applies to the real functions. Why would some poles which are not on the real line affect the value of a real integral which still can be seen as the area under the curve defined by the integrand?
I know that some integrals which can be solved by contour integration can be also solved in other ways, for example the most simple one:
$$I=\int_{-\infty}^\infty \frac{dx}{1+x^2}=\pi$$
Using $(1+i)(1-i)=1+x^2$ makes the contour integration very simple, however it's also simple to show that $I=4\int_0^1 \frac{dx}{1+x^2}$ and connect the following integral to the definition of arcangent and Lebniz series.
But not all of the integrals can be easily solved that way. What about:
$$\int_{-\infty}^\infty \frac{\cos x dx}{1+x^2}=\frac{\pi}{e}$$
Can this integral be solved by real methods? Are there real integrals with closed forms, which can only be evaluated by contour integration? And if they exist, then how can it be explained?
To be clear, I understand that we can numerically confirm the value to any precision by just using numerical methods for the real integral in question. Except for some highly oscillatory integrands (probably).