Where is my mistake of calculating $\int_0^{2\pi}\frac{d\varphi}{(2+\cos \varphi)^2}$? I have the integral:
$$\int_0^{2\pi}\frac{d\varphi}{(2+\cos \varphi)^2}$$
putting standard substitutions:
$$\cos\varphi =\frac{1}{2}\left(z+\frac{1}{z}\right) \\ d\varphi = \frac{idz}{z}$$
and simplifying, I got:
$$2i\oint\limits_{|z| = 1}\frac{dz}{z^2+2z+1}$$
and solving the denumerator I finally got:
$$2i\oint\limits_{|z| = 1} \frac{dz}{(z+1)^2}$$
which means there is second - order pole at $z = -1$
but applying the formula for residue calculating I got:
$$\lim_{z \to -1}\frac{d}{dz} \frac{(z+1)^2}{(z+1)^2}$$
but it means thet the fraction tends to $1$ and therefore the derivarive tends to 0 as the whole limit and therefore the residue :/ Where am I wrong?
 A: All your computations are mistaken:
$$\int_{0}^{2\pi}\frac{d\theta}{(2+\cos\theta)^2}=\int_{0}^{2\pi}\frac{d\theta}{\left(2+\frac{e^{i\theta}+e^{-i\theta}}{2}\right)^2}=\oint_{\|z\|=1}\frac{-i\,dz}{z\left(2+\frac{z+z^{-1}}{2}\right)^2} $$
and the last integral equals
$$ \oint \frac{-4iz\,dz}{\left(z^2+4z+1\right)^2}=8\pi\operatorname*{Res}_{z=\sqrt{3}-2}\frac{z}{(z^2+4z+1)^2}=\color{red}{\frac{4\pi}{3\sqrt{3}}} $$
which is simple to prove also by real techniques, by exploiting the periodicity of the cosine function and the substitution $\theta=\arctan u$ or $\theta=2\arctan\frac{u}{2}$. Or we may notice that for any $a>1$ we have
$$\int_{0}^{2\pi}\frac{d\theta}{a+\cos\theta}=\frac{2\pi}{\sqrt{a^2-1}}$$
hence by differentiating both sides with respect to $a$ we get
$$\forall a>1,\qquad \int_{0}^{2\pi}\frac{d\theta}{(a+\cos\theta)^2}=\frac{2\pi a}{(a^2-1)^{3/2}} $$
and the previous result follows by evaluating both sides at $a=2$.
A: Note that 
$$\begin{align}
\frac{1}{(2+\cos(\phi))^2}\,d\phi&=\frac{1}{\left(2+\frac{z+z^{-1}}{2}\right)^2}\,\frac{1}{iz}\,dz\\\\
&=\frac{-i4z}{\left(z^2+4z+1\right)^2}\,dz\\\\
&=\frac{-i4z}{(z+2+\sqrt3)^2(z+2-\sqrt3)^2}\,dz\\\\
\end{align}$$
There is a second order pole at $z=-2+\sqrt 3$ inside the unit circle.  Can you evaluate the reside?
A: Hint: You forgot the power $2$ in denominator, and a minus as well! so need a $-2z$ in numerator.
A: $\newcommand{\bbx}[1]{\,\bbox[15px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

Besides the 'complex evaluation', a 'real evaluation' can be performed as follows:

\begin{align}
\int_{0}^{2\pi}{\dd\varphi \over \bracks{2 + \cos\pars{\varphi}}^{\,2}} & =
\int_{-\pi}^{\pi}{\dd\varphi \over \bracks{2 - \cos\pars{\varphi}}^{\,2}} =
2\int_{0}^{\pi}{\dd\varphi \over \bracks{2 - \cos\pars{\varphi}}^{\,2}}
\\[5mm] & =
2\int_{-\pi/2}^{\pi/2}{\dd\varphi \over \bracks{2 + \sin\pars{\varphi}}^{\,2}}
\\[5mm] & =
2\int_{0}^{\pi/2}\braces{%
{1 \over \bracks{2 + \sin\pars{\varphi}}^{\,2}} +
{1 \over \bracks{2 - \sin\pars{\varphi}}^{\,2}}}\dd\varphi
\\[5mm] & =
2\int_{0}^{\pi/2}
{8 + 2\sin^{2}\pars{\varphi} \over \bracks{4 - \sin^{2}\pars{\varphi}}^{\,2}}\,
\dd\varphi
\\[5mm] & =
2\int_{0}^{\pi/2}{8\sec^{2}\pars{\varphi} + 2\tan^{2}\pars{\varphi} \over
\bracks{4\sec^{2}\pars{\varphi} - \tan^{2}\pars{\varphi}}^{\,2}}\sec^{2}\pars{\varphi}\,\dd\varphi
\\[5mm] & =
2\int_{0}^{\pi/2}{10\tan^{2}\pars{\varphi} + 8 \over
\bracks{3\tan^{2}\pars{\varphi} + 4}^{2}}\sec^{2}\pars{\varphi}\,\dd\varphi
\\[5mm] & \stackrel{x\ =\ \tan\pars{\varphi}}{=}\,\,\,
{2 \over 9}\int_{0}^{\infty}{10x^{2} + 8 \over \pars{x^{2} + 4/3}^{2}}\,\dd x =
{1 \over 9}\int_{-\infty}^{\infty}
{10x^{2} + 8 \over \pars{x^{2} + 4/3}^{2}}\,\dd x
\\[5mm] & =
{1 \over 9}\,2\pi\ic\lim_{x \to \root{4/3}\ic}\totald{}{x}{10x^{2} + 8 \over \pars{x + \root{4/3}\ic}^{2}} = \bbx{{4\root{3} \over 9}\,\pi} \approx 2.4184
\end{align}
