Counterpart of Weierstrass theorem

Assume that $(X,\tau)$ is a topological space and assume that every continuous mapping $f$ of $X$ into real line $\mathbb{R}$ achieves its maximum. Under which conditions on $\tau$, the space $X$ is compact. It can be easily prove that, $X$ is compact, provided that $\tau$ is a metric topology in $X$.

Is for example this true for the Hausdorff spaces?

-
There's some non-Hausdorff spaces it does not hold for. You'll probably want some kind of countability condition on the topology of the space. – Ryan Budney Nov 30 '12 at 7:08
@Budney This question was for me interesting from long time ago when I was a student. The question is not related to any research; it is only solely interesting. – djoke Nov 30 '12 at 7:18

You look for the notion of a pseudocompact space.

-
A further question: if $X$ is pseudocompact, is there a compact topology on $X$ with the same real-valued functions? – Pietro Majer Nov 30 '12 at 9:18

In this answer, I will assume that all spaces are Hausdorff. It is well known that a space is compact if and only if it is pseudocompact and realcompact[See The Stone Cech Compactification by Russel Walker p.34]. A space is realcompact if and only if it can be embedded in $\mathbb{R}^{I}$ as a closed subspace. Also, in the topology book by Dugundji, the author proves that a space is compact if and only if it is countably compact and metacompact. Here metacompact means that every open covering has a point-finite open refinement (A cover $\mathcal{U}$ of $X$ is point finite if $\{U\in\mathcal{U}|x\in U\}$ is finite for each $x\in X$). In particular, a space is compact if and only if it is pseudocompact and metacompact. Since Metrizable implies paracompact implies metacompact, every pseudocompact metrizable space is compact.

For an easy example of a completely regular pseudocompact space that is not compact try the set $\omega_{1}$ of all countable ordinals. In fact, it can easily be shown that every continuous map $f:\omega_{1}\rightarrow\mathbb{R}$ is eventially constant.

-
And I cannot resist to add a reference to the <a href="en.wikipedia.org/wiki/Long_line"; rel="nofollow">long line</a>, locally isomorphic to R, sequentially compact, but not compact. – Feldmann Denis Nov 30 '12 at 14:47

Any countably compact space $X$ has this property. The image of a continuous real valued function of $X$ is a countably compact subset of $\mathbb{R}$, hence compact because it is Lindelöf, so it has maximum and minimum.

-
@Pietro Majer. See the email. The metric space has this property, and need not be a countably compact space. – djoke Nov 30 '12 at 9:40
Indeed, I am saying that countably compact is a simple sufficient condition for all real valued continuous function have maximum. The example of a pseudocompact, non countably compact space $X$ should be in "counterexamples in topology". – Pietro Majer Nov 30 '12 at 10:35