This can be done by time stamping a particular event (when the energy for this character last changed) and keeping that time stamp / energy level after the change in a database.
When the user views his character, you take (current time) - (timestamp time) and base the user's energy level off of that (you can update the database while you are at it).
This method doesn't rely on cron and is only updated when the user is visiting the website (the only time the user's energy really needs to be updated). This method requires you to have a new table in your database that holds energy and timestamp for each user.
To recap (in order):
1. User's energy level changes (perhaps the user was hit or something).
2. You place the user's new energy level into a database with a timestamp of the current time.
3. Whenever your game needs to display this user's particular energy level (I am assuming this ONLY happens when the specific user is interacting with the system), you game fetches the time stamp and new energy level from the database.
4. Determine the difference between the current time and the time stamp and multiply it by some value to get the user's energy level. NE = ((current time) - (timestamp))*rate_of_energy_recharge
5. Take (NE) from above and update user's energy in the database (i.e. probably where your user table or attribute table is I am guessing) ~ NOT the timestamp time.
6. When enough time has elapsed or a the user's energy level has changed again (i.e. the user has been hit again), update the user's energy / timestamp in the energy timestamp table.
That would be the basic and most obvious setup here. A good example of #4 equation:
This method will work best if your script has ONE function to update a user's energy level. If your script update's the user's energy level from multiple locations, then you will want to include the code you come up with that calculates the user's energy from the timestamp db into the header / global portion of your script (so it is loaded every time to ensure that things such as shops work correctly).