Sphpera is Static php performance analysis tool designed for finding potentially the slowest methods and classes based on functions / methods called in them.
- detection of global function calls
- multiplication for calls in cycles
- custom configuration
- detection of class methods calls
- HTML output similar to PHPUnit
- detection of multiple implementations - when some interface or class has multiple implementations and there is only this interface injected, we have to decide which implementation will be used for analysis (default the slowest, can be overridden via configuration)
- multiplication for calls in array_map and similar cycle-style functions
This project should not be run as a dependency, but as separate project. Create some directory for it:
mkdir sphpera
cd sphperaand follow one of next steps:
The recommended way is to install this project via composer.
composer require lulco/sphperaYou can also clone this project directly. Use this for contribution.
git clone git@github.com:lulco/sphpera.git .
composer install Note: Following examples describe how to use sphpera when it is installed via composer.
Run command:
vendor/bin/sphpera analyse dir1 dir2Generate coverage-like HTML report:
vendor/bin/sphpera analyse dir1 dir2 --format=html --output=build/sphpera-reportGenerate JSON report:
vendor/bin/sphpera analyse dir1 dir2 --format=jsonGenerate JSON baseline snapshot:
vendor/bin/sphpera analyse dir1 dir2 --format=json --output=build/sphpera/baseline.jsonCreate your own configuration file where you set the score for functions / methods and default score. Then use this configuration file as option in analyse command.
vendor/bin/sphpera analyse dir1 dir2 --config=path_to_custom_config_fileSphpera has built-in scoring defaults (HTTP/DB/FS/process/CPU-heavy operations). Your config has priority over built-ins (first match wins). If you define a matching pattern, that score is used and evaluation for that node stops.
--format=text(default): top N scored methods--format=json: structured result with class/method/line contributions--format=html: report with index, class detail, and line heatmap--compare-baseline=...: compares current run against JSON baseline and shows deltas in reports
HTML report has two tabs:
Dashboard: top classes/methods and deltasIndex: directory/file navigation with aggregated metrics (min,avg,median,max)
Index uses risk coloring (green/yellow/orange/red) based on normalized score mix:
- 50% median score
- 35% average score
- 15% maximum score
Sphpera uses PHPStan ReflectionProvider for method return type inference where available
(for example chained calls like $pdo->query(...)->fetchAll()), with AST heuristics
as fallback.
Report contains only files from input dirs (for example src), but analysis also parses
vendor/ (if present) to improve external-call scoring context.