I’m trying to make a function in PHP that counts how many times a function is used by all the users.
If this function has been used, let’s say, 30 times, then it should block access for some minutes and then reset the counter to 0.
Is this possible in PHP?
This is no problem, even trivial, if all usages take place within a single process. You just use a global or static counter variable and increment it. As long as the process is running you can access that value.
However I assume you are talking about a web environment and the php function being part of a script executed by the http server? Sorry, but you don’t mention that…
In that case things get more complex, since it is not a single process any more. You require some sort of persistent storage. Typical scenarios use a database, a file or shared memory for this. These allow different processes to access a shared counter value.