How to make a function occurs for one time?

It is executed only once. You see it multiple times because contents of those widgets are fetched via AJAX which loads WordPress in the ajax request again and hence it is echo’ed once again but it is executed only once per load. Makes sense?