I'm working with a site that was built in Drupal and generally runs well. After some optimization it takes 20-75MB of memory and 0.5-2s for most requests. But once in a while it will take 15-20s and the process will run over 1GB+ memory usage.
I've tried tracing the time and memory usage at the beginning and end of the PHP execution (putting the code in Drupal's index.php) and it shows nothing unusual (it reports a difference of 1 seecond between the start and end, and memory usage goes up 72MB in one example). Somehow PHP is using a lot of resources but not within the actual PHP code.
This was first observed with apache. Moving to a new server (using standard Ubuntu packages) made the site a bit more reliable, but it still happens. Even after switching to nginx+php-fpm and turning off apache entirely, the php-fpm processes show the same memory usage pattern. Other than standard PHP modules the only extras are memcache, stats, and xhprof.
What could reveal why PHP is using so much memory outside the script itself?