Skip to content

Commit 8558ed7

Browse files
authored
init (#1)
* init * flat roots * add ObjectDeallocationChecker * MemoryScanner: support resolving root reference that excludes some objects * ObjectDeallocationChecker: exclude secondary leaks by default * finish ObjectDeallocationChecker * MemoryScanner: simplify path segment labels for properties * MemoryScanner: preserve references in exported objects * ObjectDeallocationChecker: improve explanation formatting * fix type error * ObjectDeallocationChecker: remove unnecessary trailing newline from explanation * composer: add composer validate --strict
1 parent 34a8502 commit 8558ed7

36 files changed

+1769
-0
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[*]
2+
charset = utf-8
3+
end_of_line = lf
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true
6+
indent_style = space
7+
indent_size = 4

.editorconfig-checker.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Exclude": [
3+
"snapshots"
4+
]
5+
}

.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* text=auto
2+
3+
/.github export-ignore
4+
/tests export-ignore
5+
6+
/.editorconfig export-ignore
7+
/.gitattributes export-ignore
8+
/.gitignore export-ignore
9+
/phpcs.xml.dist export-ignore
10+
/phpstan.neon.dist export-ignore
11+
/phpunit.xml.dist export-ignore

.github/workflows/checks.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Checks
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- "master"
7+
- "v[0-9]"
8+
jobs:
9+
checks:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
steps:
14+
-
15+
name: Checkout code
16+
uses: actions/checkout@v2
17+
-
18+
name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: 8.4
22+
-
23+
name: Install dependencies
24+
run: composer install --no-progress --prefer-dist --no-interaction
25+
26+
-
27+
name: Run checks
28+
run: composer check
29+
30+
tests:
31+
runs-on: ubuntu-latest
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
php-version: [ '8.1', '8.2', '8.3', '8.4' ]
36+
dependency-version: [ prefer-lowest, prefer-stable ]
37+
steps:
38+
-
39+
name: Checkout code
40+
uses: actions/checkout@v2
41+
-
42+
name: Setup PHP
43+
uses: shivammathur/setup-php@v2
44+
with:
45+
php-version: ${{ matrix.php-version }}
46+
-
47+
name: Update dependencies
48+
run: composer update --no-progress --${{ matrix.dependency-version }} --prefer-dist --no-interaction
49+
-
50+
name: Run tests
51+
run: composer check:tests

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.idea/
2+
/cache/
3+
/vendor/
4+
5+
/composer.lock
6+
/phpstan.neon
7+
8+
!/cache/.gitkeep

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ShipMonk PHP Memory Scanner
2+
3+
A lightweight PHP library for analyzing memory usage and finding memory leaks in PHP applications.
4+
5+
This package provides tools to:
6+
7+
1. Scan PHP memory for objects and their references
8+
2. Track object allocations and detect objects that aren't properly deallocated
9+
3. Find reference paths from global roots to leaked objects
10+
4. Generate detailed explanations of why objects aren't being deallocated
11+
12+
The core functionality relies on traversing the PHP object graph from various memory roots (like superglobals, functions, classes, etc.) to detect what's keeping your objects in memory.
13+
14+
Perfect for debugging memory leaks in long-running PHP applications, especially when working with frameworks or code that maintains complex object relationships.
15+
16+
## Installation:
17+
18+
```sh
19+
composer require shipmonk/memory-scanner
20+
```
21+
22+
## Contributing
23+
- Check your code by `composer check`
24+
- Autofix coding-style by `composer fix:cs`
25+
- All functionality must be tested

cache/.gitkeep

Whitespace-only changes.

composer-dependency-analyser.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types = 1);
2+
3+
use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
4+
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;
5+
6+
$config = new Configuration();
7+
$config->ignoreErrorsOnExtensions(['ext-pcntl', 'ext-xdebug'], [ErrorType::SHADOW_DEPENDENCY]);
8+
9+
return $config;

composer.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "shipmonk/memory-scanner",
3+
"description": "Lightweight PHP library for analyzing memory usage, tracking object references, and debugging memory leaks",
4+
"license": [
5+
"MIT"
6+
],
7+
"require": {
8+
"php": "^8.1"
9+
},
10+
"require-dev": {
11+
"editorconfig-checker/editorconfig-checker": "^10.7.0",
12+
"ergebnis/composer-normalize": "^2.47.0",
13+
"phpstan/phpstan": "^2.1.14",
14+
"phpstan/phpstan-phpunit": "^2.0.6",
15+
"phpstan/phpstan-strict-rules": "^2.0.4",
16+
"phpunit/phpunit": "^10.5.46",
17+
"shipmonk/composer-dependency-analyser": "^1.8.2",
18+
"shipmonk/name-collision-detector": "^2.1.1",
19+
"shipmonk/phpstan-rules": "^4.1.1",
20+
"slevomat/coding-standard": "^8.18"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"ShipMonk\\MemoryScanner\\": "src/"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"ShipMonkTests\\MemoryScanner\\": "tests/"
30+
}
31+
},
32+
"config": {
33+
"allow-plugins": {
34+
"dealerdirect/phpcodesniffer-composer-installer": true,
35+
"ergebnis/composer-normalize": true
36+
},
37+
"sort-packages": true
38+
},
39+
"scripts": {
40+
"check": [
41+
"@check:composer",
42+
"@check:ec",
43+
"@check:cs",
44+
"@check:types",
45+
"@check:tests",
46+
"@check:dependencies"
47+
],
48+
"check:composer": [
49+
"composer normalize --dry-run --no-check-lock --no-update-lock",
50+
"composer validate --strict"
51+
],
52+
"check:cs": "phpcs",
53+
"check:dependencies": "composer-dependency-analyser",
54+
"check:ec": "ec src tests",
55+
"check:tests": "phpunit tests",
56+
"check:types": "phpstan analyse -vv",
57+
"fix:cs": "phpcbf"
58+
}
59+
}

0 commit comments

Comments
 (0)