This probably isn't a FileMaker specific problem. Web served PHP has a safety valve that keeps scripts from running indefinitely and consuming all the computational resources of your web server. The default time limit for a PHP generated page request is 30 seconds. Check out PHP: set_time_limit - Manual to increase the limit.
As far as the intermittent behavior, it is quite possible that you have a slow database query or script that, when starting cold, goes over the time limit. If you run the same query moments later, it typically takes less time because of caching that automatically happens in FMS and the operating system.
There might also be something sluggish about your server setup. If using a HDD, make sure the drives are not sleeping. You might be waiting a few seconds for a drive to spin up after going into a low power mode. Even better would be using SSDs on your server. Beyond that, work on tuning your script or query so that it doesn't take so long to run.
As you mention it looks like the server goes into some kind of idle/sleep state.
It doesn't matter what kind of query I run as long as it happens at least every minute. Even when i change the query the server responds fast. So i don't think it has anything to do with the cache.
Is this a typical config error on the IIS webserver?