# noisebynorthwest/php-spx architecture

> Architecture diagram of the GitHub repository noisebynorthwest/php-spx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/noisebynorthwest/php-spx
- Repository: https://github.com/noisebynorthwest/php-spx

## Overview

SPX is a PHP profiling extension. A CLI environment setting or HTTP request configuration enables profiling; the extension hooks PHP execution, collects call and metric data, then emits a flat report or stores a full report for the bundled web UI’s report listing and analysis. The principal runtime stages are PHP integration, configuration and hook dispatch, profiling/metric collection, and report delivery. Source excerpts are incomplete, so some README-documented UI and report-storage links are shown as unverified rather than asserted as inspected calls.

Main entry points: [`src/php_spx.c`](https://github.com/noisebynorthwest/php-spx/blob/master/src/php_spx.c) (SPX extension), [`src/spx_profiler_tracer.c`](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_profiler_tracer.c) (Call tracer), [`src/spx_reporter_fp.c`](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_reporter_fp.c) (Flat report), [`src/spx_metric.c`](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_metric.c) (Metric collection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integration["PHP integration"]
  node_extension["SPX extension<br/>[php_spx.c]"]
  node_config["Profile configuration<br/>[spx_config.c]"]
  node_php_api["PHP hooks and API<br/>[spx_php.c]"]
end

subgraph group_capture["Profile capture"]
  node_sampler["Sampling profiler"]
  node_tracer["Call tracer"]
  node_metrics["Metric collection<br/>[spx_metric.c]"]
end

subgraph group_reporting["Reporting"]
  node_flat_report["Flat report<br/>[spx_reporter_fp.c]"]
  node_full_report["Full report"]
  node_trace_report["Trace report"]
  node_http_ui["HTTP control and UI<br/>[php_spx.c]"]
  node_report_files[("Report files")]
end

subgraph group_support["Runtime support"]
  node_resource_stats["Process statistics"]
  node_output_stream["Output streams"]
  node_formatting["Value and table formatting<br/>[spx_fmt.c]"]
  node_hash_map["Function table map<br/>[spx_hmap.c]"]
end

node_cli(("CLI script"))
node_browser(("Browser session"))
node_php["PHP runtime"]

node_cli -.->|"enables profiling"| node_extension
node_browser -.->|"configures request"| node_extension
node_php -.->|"runs extension"| node_extension
node_extension -->|"loads settings"| node_config
node_extension -->|"hooks execution"| node_php_api
node_extension -.->|"selects profiler"| node_sampler
node_extension -.->|"selects profiler"| node_tracer
node_tracer -->|"collects metrics"| node_metrics
node_metrics -->|"reads process stats"| node_resource_stats
node_tracer -->|"indexes functions"| node_hash_map
node_tracer -.->|"notifies events"| node_flat_report
node_tracer -.->|"notifies events"| node_full_report
node_tracer -.->|"notifies events"| node_trace_report
node_flat_report -->|"prints report"| node_output_stream
node_flat_report -->|"formats values"| node_formatting
node_full_report -.->|"writes report data"| node_report_files
node_trace_report -.->|"writes trace"| node_output_stream
node_http_ui -.->|"lists and serves reports"| node_report_files
node_browser -.->|"views analysis"| node_http_ui

click node_extension "https://github.com/noisebynorthwest/php-spx/blob/master/src/php_spx.c"
click node_config "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_config.c"
click node_php_api "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_php.c"
click node_sampler "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_profiler_sampler.c"
click node_tracer "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_profiler_tracer.c"
click node_metrics "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_metric.c"
click node_resource_stats "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_resource_stats-linux.c"
click node_flat_report "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_reporter_fp.c"
click node_full_report "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_reporter_full.c"
click node_trace_report "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_reporter_trace.c"
click node_http_ui "https://github.com/noisebynorthwest/php-spx/blob/master/src/php_spx.c"
click node_output_stream "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_output_stream.c"
click node_formatting "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_fmt.c"
click node_hash_map "https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_hmap.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_extension,node_config,node_php_api,node_browser toneBlue
class node_sampler,node_tracer,node_metrics toneAmber
class node_flat_report,node_full_report,node_trace_report,node_http_ui,node_report_files toneMint
class node_resource_stats,node_output_stream,node_formatting,node_hash_map toneRose
class node_cli,node_php toneIndigo
```

## Components

### PHP integration

- [SPX extension](https://github.com/noisebynorthwest/php-spx/blob/master/src/php_spx.c): `src/php_spx.c`
- [Profile configuration](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_config.c): `src/spx_config.c`
- [PHP hooks and API](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_php.c): `src/spx_php.c`

### Profile capture

- [Sampling profiler](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_profiler_sampler.c): `src/spx_profiler_sampler.c`
- [Call tracer](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_profiler_tracer.c): `src/spx_profiler_tracer.c`
- [Metric collection](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_metric.c): `src/spx_metric.c`

### Reporting

- [Flat report](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_reporter_fp.c): `src/spx_reporter_fp.c`
- [Full report](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_reporter_full.c): `src/spx_reporter_full.c`
- [Trace report](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_reporter_trace.c): `src/spx_reporter_trace.c`
- [HTTP control and UI](https://github.com/noisebynorthwest/php-spx/blob/master/src/php_spx.c): `src/php_spx.c`
- **Report files**

### Runtime support

- [Process statistics](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_resource_stats-linux.c): `src/spx_resource_stats-linux.c`
- [Output streams](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_output_stream.c): `src/spx_output_stream.c`
- [Value and table formatting](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_fmt.c): `src/spx_fmt.c`
- [Function table map](https://github.com/noisebynorthwest/php-spx/blob/master/src/spx_hmap.c): `src/spx_hmap.c`

### Other components

- **CLI script**
- **Browser session**
- **PHP runtime**

## Connections

- CLI script → SPX extension: enables profiling
- Browser session → SPX extension: configures request
- PHP runtime → SPX extension: runs extension
- SPX extension → Profile configuration: loads settings (evidence: `src/php_spx.c`)
- SPX extension → PHP hooks and API: hooks execution (evidence: `src/php_spx.c`)
- SPX extension → Sampling profiler: selects profiler
- SPX extension → Call tracer: selects profiler
- Call tracer → Metric collection: collects metrics (evidence: `src/spx_profiler_tracer.c`)
- Metric collection → Process statistics: reads process stats (evidence: `src/spx_metric.c`)
- Call tracer → Function table map: indexes functions (evidence: `src/spx_profiler_tracer.c`)
- Call tracer → Flat report: notifies events
- Call tracer → Full report: notifies events
- Call tracer → Trace report: notifies events
- Flat report → Output streams: prints report (evidence: `src/spx_reporter_fp.c`)
- Flat report → Value and table formatting: formats values (evidence: `src/spx_reporter_fp.c`)
- Full report → Report files: writes report data
- Trace report → Output streams: writes trace
- HTTP control and UI → Report files: lists and serves reports
- Browser session → HTTP control and UI: views analysis
