too many connection error mysql: how to calculate max_connections
Before deciding on value for max_connections I suggest that you look at WHY it reached the max_connection condition. A bunch of sleeping/idle connection due to loose coding is very common cause. Check if you have proper value for wait_timeout and adjust if this is your symptom.

Besides that, I would check for INSERT/UPDATE query that holds table locks for too long, as well as slow queries that get piled up once in a while.