From recent experience, I got 7 kills with a shotgun and picked up my first shotgun ribbon. I was kicked by an admin shortly after because of some no shotgun rule on the rented server.
In the Battlelog website I noticed I didn't have the ribbon. However, after a few minutes another page refresh showed I had unlocked the ribbon.
Going by other observations with ribbons and weapon kills, I would say that the rewards etc are updated periodically rather than instantly. That seems pretty much true for games in progress (i.e. get a kill with a gun, then immediately refresh the Battlelog website doesn't increase your kill count for a gun).
I can't say for certain but it does appear that the stats are updated when the game ends. If you get kicked from a game, you need to wait for the game to end in order to update your stats.
To complicate matters, if you rejoin a server your previous progress is not wiped. For example, if you get 5 kills, leave, rejoin, and get another 5 kills then your stats will update with 10 kills. This is the same for ribbons (I got a squad wipe ribbon either side of a rejoin, and my ribbons increased by 2).
I don't know what will happen if the server crashes or is taken down mid-game, my experiences above are through getting kicked by an admin or leaving through the menu. This also seems to match how both the Medal of Honor games updated servers.