[HN Gopher] Phptop: Simple PHP ressource profiler, safe and usef...
       ___________________________________________________________________
        
       Phptop: Simple PHP ressource profiler, safe and useful for
       production sites
        
       Author : kadrek
       Score  : 92 points
       Date   : 2025-06-05 08:52 UTC (14 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | 127dot1 wrote:
       | Is it compatible with nginx+php-fpm stack?
        
         | tarjei_huse wrote:
         | Looks likely. The server part of it is just a PHP-hook.
        
           | joshstrange wrote:
           | Yeah, from a brief glance at this, it just adds a file that
           | runs on every request which logs out to the php error log and
           | then there's another script that can parse that error log.
        
             | zerodeux wrote:
             | Exactly.
             | 
             | I'm the author, it's funny this thing pops up now, it was
             | written +15 years ago and is barely maintained (but AFAKI
             | still works).
             | 
             | The metrics collected are close to those from PHP-FPM (CPU
             | user/sys, clock time, peak memory) + the wpdb hook because
             | I had to profile _lots_ of WP.
             | 
             | The most interesting part is the 'phptop' tool itself which
             | actually parse the logs and make some useful histograms.
             | 
             | Its main force I think it's that it's very lightweight (500
             | lines of Perl, fast and efficient regexes), works
             | everywhere (very old Perl will do), and gives results
             | instantly. My usecase used to be : apt install phptop, wait
             | (at least) 1min for data collection, get useful histogram.
             | It's also obviously very easy to uninstall.
             | 
             | It does pollute the error log, but it's the most simple and
             | universal data sink I could think of, and well it's a hack
             | in the end.
             | 
             | Patches still welcome anyway :).
        
         | rthnbgrredf wrote:
         | Yes, but php-fpm already has this kind of information for you:
         | https://www.inanzzz.com/index.php/post/6cn7/formatting-php-f...
         | 
         | You can print the time, cpu and memory usage per request and
         | build metrics based on these outputs. This can be done in any
         | major cloud, with open source tooling and even with simple
         | linux coretuils. One tool to visualize such metrics is Grafana.
        
         | zerodeux wrote:
         | It is compatible with Nginx+FPM. It won't use the PHP-FPM
         | specific logs (and thus does not impose any specific value from
         | you for the access.format PHP-FPM setting). But it has to
         | figure out where your app's error log is.
        
       | basilgohar wrote:
       | This is interesting, but it seems it's more useful for WordPress
       | sites with the specific WPDB logic they have.
       | 
       | It'd be more interesting if, instead, they could intercept PDO
       | queries and add profiling to those, for example.
       | 
       | Still, free code is free code. I don't want to look down upon it,
       | just that the utility for my case is limited.
        
         | zerodeux wrote:
         | The wpdb logic is an addon and only triggers if wpdb is found.
         | Phptop might still be useful in the general case to quickly and
         | cheaply find CPU hotspots.
         | 
         | Nowadays it would be necessary to also show the various
         | Curl/API calls because they're so omnipresent and impactfull on
         | PHP sites (as wait time and not CPU time)... But AFAIK it's
         | pretty hard to intercept them in a generic way.
        
       | nchmy wrote:
       | Its not evident to me what this does... It says that it "prints
       | per query and average metrics", but it seems to just output some
       | extremely generic stats. Does "query" actually mean request here?
       | 
       | I see there's a wordpress-specific wpdb mechanism - though it
       | just seems to report total time spent on queries, and the slowest
       | query. Surely something like Query Monitor is a far better tool
       | for that?
       | 
       | A tool that everyone should be aware of and using is php-spx -
       | its absolutely glorious for performance profiling/investigation.
       | xhgui is similar, but bulkier and (in my experience) less
       | accurate/insightful.
       | 
       | https://github.com/NoiseByNorthwest/php-spx
        
         | BafS wrote:
         | I can't praise SPX enough, it has saved my ass multiple times.
         | The UI is great too.
        
         | xd wrote:
         | From a quick skim of the repo it looks to be injecting
         | phptop_hook.php into any call to a php file with
         | auto_prepend_file in php.ini. phptop_hook.php generates some
         | stats on how long it took the php file to process and stores
         | this via error_log() which can then be queried with the perl
         | script phptop.
        
         | zerodeux wrote:
         | Author here.
         | 
         | "Query" does mean "HTTP request" in the summary. It's reported
         | as "Hits" in the stats. Sorry for the incoherent wording ...
         | 
         | The SQL/wpdb support was added afterwards, and it shows because
         | data is only collected but not used/displayed in the
         | histograms.
         | 
         | Phptop is wayyy simpler and not even comparable to SPX, but you
         | can install it in a few sec, use it 5min, uninstall it, and
         | solve lots of common perf problem. That was my use case (it'as
         | ancient code and I barely use it nowadays).
        
           | nchmy wrote:
           | Thanks for the clarification!
           | 
           | What do you use now?
        
       ___________________________________________________________________
       (page generated 2025-06-05 23:00 UTC)