4. Given the ellipse $\frac{x^{2}}{a^{2}}+\frac{y^{2}}{b^{2}}=1(a>b>0), F_{1}$ and $F_{2}$ are its left and right foci, and $P$ is any point on the ellipse. If $\triangle P F_{1} F_{2}$ is a right triangle, then the number of possible points $P$ is ( ) .
(A) 4
(B) 6
(C) 4 or 6
(D) 4, 6, or 8
4.D.
(1) If $\angle P F_{1} F_{2}=90^{\circ}$, obviously, there are 2 points $P$.

Similarly, if $\angle P F_{2} F_{1}=90^{\circ}$, there are 2 points $P$.
(2) If $\angle F_{1} P F_{2}=90^{\circ}$, then we have
$\left|F_{1} F_{2}\right|^{2}=\left|P F_{1}\right|^{2}+\left|P F_{2}\right|^{2} \geqslant 2\left(\frac{\left|P F_{1}\right|+\left|P F_{2}\right|}{2}\right)^{2}$.
That is, $2 c^{2} \geqslant a^{2}, e \geqslant \frac{\sqrt{2}}{2}$.
Therefore, when $e \in\left(\frac{\sqrt{2}}{2}, 1\right)$, by symmetry, there are 4 points $P$; when $e=\frac{\sqrt{2}}{2}$, there are 2 points $P$, which are the endpoints of the minor axis; when $e \in\left(0, \frac{\sqrt{2}}{2}\right)$, there are no points $P$ that satisfy the condition.