How does an application performance monitoring tool like New Relic RPM work? How can it figure out all that information about your application? If someone was to build something similar for a PHP application where would be a good place to start? (I know New Relic for PHP is available, I'm interested in how to build one myself).