I'll assume that you meant "idle game".
The basics go roughly like this: When exiting the game, save the time it was closed at. You can use current_time to get the current time.
When opening it again, calculate the difference between the time now and the time when it was closed.
Use that with a formula that provides you with the average gain during that time period. For example, if you gain 5 gold for every second while the game is closed and had it closed for 60 seconds, you'd gain 5 * 60 = 300 gold.