Does compact orbit imply periodicity? A continuous dynamical system on a metric space $X$ is given by:

$\varphi : \mathbb{R} \times X \rightarrow X$ - continuous s.t. 
$\varphi (0,x) = x$ for every $x \in X$
$\varphi (t, \varphi(s,x) ) = \varphi(s+t, x)$ for all $s, t \in
\mathbb{R}, \ \ x \in X $

and 

$\gamma(x) = \{y \in X| \exists t\in \mathbb{R}; \varphi(t,x) = y \}$
  is the orbit of $x$.
$x \in X$ is periodic iff $x =\varphi(T,x)$ for some $0 \neq T \in \mathbb
 R$.


The question is the following: 

Assume that $x$ is periodic. Show that $\gamma(x)$ is compact. Is the converse true?


For the first part, if $x$ is periodic of period $T \ge 0$ then $\gamma(x)= \varphi (\{x\} \times[-T,T])$ which is an image of a compact set, hence compact.
However, I am not sure about the converse. All I know is that for some sequence $t_n \to \infty$, $\varphi(t_n,x) \to x'$ for some $x' \in \gamma(x)$. Hence $\exists t' \in \mathbb{R}$ such that $\varphi (t',x) = x'$. On the other hand, we also have a continuous bijection from $\mathbb R$ to a compact set. At first sight this does not seem enough though. 
Thank you.
P.S. The problem is from Bhattia & Szego: Stability Theory of Dynamical Systems
 A: While the answer of @Moishe Kohan answers an even more general question, in the meantime I was able to solve the particular problem (hopefully correctly). It makes use of the Baire category theorem and the following two lemmas:


Lemma 1. Assume that the $x$ is not periodic and $\gamma(x)$ is compact. Then for any $x' \in\gamma(x) $ there exists a real sequence $(T_n) , T_n \to \infty$ such
that $\varphi(T_n, x) \to x'$.

Proof: Noticing that due to compactness, the sequence $(\varphi(n,x))_n$ converges up to a subsequence, denote its limit as $x'' \in \gamma(x)$ (i.e. $\varphi(n(k), x) \to_{k \to \infty} x''$ for some subsequence $(n(k))_k$ of $(n)_n$). Because $x'' \in \gamma(x)$, $\exists T $ such that $x'= \varphi(T,x'')$. Now setting $(T_k)_k = (T+n(k))_k$, one can notice that $\varphi(T_k,x) \to x'$. $\square$
Applying Lemma 1 and $(\text{compactness} \implies \text{closedness}) + (\text{continuous image of a compact set is compact})$ in metric spaces, one can obtain:

Lemma 2. Assume that the $x$ is not periodic and $\gamma(x)$ is compact. For any integer $n$, the set $\varphi([n,n+1],x)$ is closed and of empty interior in $\gamma(x)$.


Now for the sake of contradiction, assume that $x$ is not periodic. Remarking that $$\gamma(x) = \bigcup_{n \in \mathbb{Z}} \varphi([n,n+1],x), $$ according to Lemma 2 and the Baire category theorem (notice that $\text{compactness of } \gamma(x) \implies \text{completeness of } \gamma(x)$), the right hand side should be of empty interior in $\gamma(x)$. This is the desired contradiction.
