Electric vehicles (EVs) are expanding quickly and widely, and, therefore, EVs can participate in reducing direct greenhouse gas emissions. The intelligent infrastructure for recharging EVs, which is microgrid-based, includes photovoltaic (PV) sources, stationary storage, and a grid connection as power sources. In this article, the energy cost optimization problem is studied, taking into account the intermittent arrival and departure of EVs. A mixed-integer linear programming is formulated as an optimization problem in a real-time operation to minimize the total energy cost, taking into consideration the physical limitations of the system. The interaction with the human-machine interface provides EV data in real-time operation, and the prediction only communicates the PV prediction profile provided by the national meteorological institute in France. The optimization is executed at each EV arrival, with the actualized data in the DC microgrid. Simulation and real-time experimental results of different meteorological conditions show that the EV user demands are satisfied, proving the feasibility of the proposed optimization problem for real-time power management.