A $P$-space is a completely regular space where the countable intersection of open sets is open. It is well known and easy to prove that that a completely regular space is a $P$-space if and only if every continuous function is locally constant.
In fact, there are several other necessary and sufficient conditions for whether a space is a $P$-space and these conditions can be found in the book Rings of Continuous Functions by Gillman and Jerison. The only compact $P$-spaces are the finite spaces: First take note that every $P$-space is zero-dimensional(i.e. it has a basis of clopen sets). If $X$ is an infinite $P$-space, and $A\subseteq X$ is a countable subset, then for each $a,b\in A$ with $a\neq b$, let $\{C_{a,b,1},C_{a,b,2}\}$ be a partition of $X$ into two clopen sets such that $a\in C_{a,b,1},b\in C_{a,b,2}$. Let $P=\bigcap_{a,b\in P}\{C_{a,b,f(a,b)}|f:A^{2}\setminus 1_{A}\rightarrow\{1,2\}\}.$ Then $P$ is a partition of $X$ into infinitely many clopen sets. Therefore $X$ cannot be compact.