binary-collections 2.0.13 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/plugins/opencode-request-logger/README.md +44 -0
- package/.venv/Lib/site-packages/pyarrow/tests/data/orc/README.md +22 -0
- package/binaries/binary-executor.cjs +307 -238
- package/binaries/clean-nodemodule.cjs +307 -238
- package/binaries/clean-nodemodules.cjs +307 -238
- package/binaries/composer.cjs +323 -0
- package/binaries/composer.cmd +2 -0
- package/binaries/composer.phar +0 -0
- package/binaries/dev.cjs +307 -238
- package/binaries/empty.cjs +307 -238
- package/binaries/git-reduce-size.cjs +307 -238
- package/binaries/javakill.cjs +307 -238
- package/binaries/kill-process.cjs +307 -238
- package/binaries/nodekill.cjs +307 -238
- package/binaries/prod.cjs +307 -238
- package/binaries/py.cjs +307 -238
- package/binaries/rmfind.cjs +307 -238
- package/binaries/rmx.cjs +307 -238
- package/binaries/submodule-token.cjs +307 -238
- package/binaries/test-cjs.cjs +307 -238
- package/binaries/test-esm.cjs +307 -238
- package/binaries/yarn-clean.cjs +307 -238
- package/binaries/yc.cjs +307 -238
- package/binaries/ycw.cjs +307 -238
- package/docs-src/binary-collections.md +1 -1
- package/docs-src/clean-github-actions-caches.md +1 -1
- package/docs-src/copy-move-file.md +1 -4
- package/docs-src/del-ps.md +1 -1
- package/docs-src/find-node-modules.md +1 -1
- package/docs-src/generate-test-ci.md +56 -0
- package/docs-src/get-latest-workflow-status.md +100 -0
- package/docs-src/git-diff.md +1 -1
- package/docs-src/git-fix.md +1 -1
- package/docs-src/git-purge.md +1 -1
- package/docs-src/install-opencode-plugins.md +86 -0
- package/docs-src/kill-night-crows.md +1 -1
- package/docs-src/node-cache-cleaner.md +2 -2
- package/docs-src/node-package-packer.md +1 -1
- package/docs-src/opencode-cli.md +155 -0
- package/docs-src/package-resolutions-updater.md +1 -1
- package/docs-src/rmpath.md +1 -1
- package/docs-src/run-by-checksum.md +1 -1
- package/docs-src/submodule-remove.md +1 -1
- package/docs-src/upload-backend.md +29 -0
- package/docs-src/vscode-cli.md +84 -0
- package/docs-src/workflow-badge.md +120 -0
- package/lib/binary-collections/config-types.cjs +17 -0
- package/lib/binary-collections/config-types.d.ts +12 -0
- package/lib/binary-collections/config-types.js +2 -0
- package/lib/binary-collections/config-types.mjs +7 -0
- package/lib/binary-collections/config.cjs +28 -8
- package/lib/binary-collections/config.d.cts +26 -8
- package/lib/binary-collections/config.mjs +2 -2
- package/lib/binary-collections/findScript.cjs +49 -25
- package/lib/binary-collections/findScript.mjs +2 -2
- package/lib/binary-collections/listScript.cjs +49 -25
- package/lib/binary-collections/listScript.mjs +2 -2
- package/lib/binary-collections.cjs +49 -25
- package/lib/binary-collections.mjs +6 -6
- package/lib/changelog.cjs +142 -4
- package/lib/changelog.mjs +9 -5
- package/lib/chunk-3T6AMFI3.mjs +52 -0
- package/lib/{chunk-2MN4VPV2.mjs → chunk-3ZF2QMDK.mjs} +4 -4
- package/lib/chunk-56BVU63B.mjs +86 -0
- package/lib/chunk-7N52Z4IJ.mjs +39 -0
- package/lib/chunk-B77D3SR4.mjs +28 -0
- package/lib/chunk-BPED62FN.mjs +115 -0
- package/lib/{chunk-RDN6HF5Z.mjs → chunk-DHFRWM2W.mjs} +1 -1
- package/lib/chunk-DPEE3FBB.mjs +146 -0
- package/lib/{chunk-MGPYPKIE.mjs → chunk-H7AE4IO3.mjs} +5 -1
- package/lib/{chunk-H44UWUFY.mjs → chunk-J4M5EL5P.mjs} +3 -0
- package/lib/chunk-KCJYREA2.mjs +67 -0
- package/lib/chunk-LACQTD5V.mjs +225 -0
- package/lib/{chunk-TBWXE7ST.mjs → chunk-NHD4HLSU.mjs} +24 -31
- package/lib/{chunk-RDGDLSPD.mjs → chunk-OWNVMKAA.mjs} +6 -5
- package/lib/chunk-SKVF4TMD.mjs +59 -0
- package/lib/{chunk-BZWVHODJ.mjs → chunk-TDUUOAQD.mjs} +5 -5
- package/lib/chunk-TP3O2JGW.mjs +88 -0
- package/lib/{chunk-FLYSZFLW.mjs → chunk-UAEKSLAX.mjs} +1 -1
- package/lib/chunk-UDZBVKXH.mjs +94 -0
- package/lib/chunk-UEOWRYAN.mjs +32 -0
- package/lib/chunk-V6PTSDW5.mjs +82 -0
- package/lib/{chunk-NQXUYO67.mjs → chunk-WNUEY6VJ.mjs} +49 -25
- package/lib/chunk-X7UVQ6ZC.mjs +183 -0
- package/lib/chunk-XW5NZAKI.mjs +82 -0
- package/lib/{chunk-LVSPEFU2.mjs → chunk-Z53IUBUN.mjs} +6 -5
- package/lib/{chunk-CD3HF3LK.mjs → chunk-Z7RM46Q4.mjs} +5 -11
- package/lib/chunk-ZB4IQ6VJ.mjs +46 -0
- package/lib/del-gradle.cjs +1 -1
- package/lib/del-gradle.mjs +22 -16
- package/lib/del-node-modules.cjs +1 -1
- package/lib/del-node-modules.mjs +148 -142
- package/lib/find-node-modules-cli.cjs +1 -1
- package/lib/find-node-modules-cli.mjs +10 -4
- package/lib/{git-diff-cli.cjs → git/git-diff-cli.cjs} +32 -12
- package/lib/{git-diff-cli.mjs → git/git-diff-cli.mjs} +7 -7
- package/lib/{git-diff.cjs → git/git-diff.cjs} +30 -10
- package/lib/{git-diff.js → git/git-diff.js} +3 -3
- package/lib/{git-diff.mjs → git/git-diff.mjs} +6 -6
- package/lib/{git-fix.cjs → git/git-fix.cjs} +142 -3
- package/lib/{git-fix.mjs → git/git-fix.mjs} +19 -14
- package/lib/{git-purge.cjs → git/git-purge.cjs} +1 -1
- package/lib/{git-purge.mjs → git/git-purge.mjs} +4 -4
- package/lib/git/user-config.cjs +139 -1
- package/lib/git/user-config.mjs +3 -1
- package/lib/{clean-github-actions-caches-cli.cjs → github-workflows/clean-github-actions-caches-cli.cjs} +46 -10
- package/lib/{clean-github-actions-caches-cli.mjs → github-workflows/clean-github-actions-caches-cli.mjs} +7 -6
- package/lib/{clean-github-actions-caches.cjs → github-workflows/clean-github-actions-caches.cjs} +46 -10
- package/lib/{clean-github-actions-caches.mjs → github-workflows/clean-github-actions-caches.mjs} +5 -4
- package/lib/github-workflows/generate-test-ci-step-cli.cjs +240 -0
- package/lib/github-workflows/generate-test-ci-step-cli.d.mts +2 -0
- package/lib/github-workflows/generate-test-ci-step-cli.mjs +132 -0
- package/lib/github-workflows/get-latest-workflow-status-cli.cjs +549 -0
- package/lib/github-workflows/get-latest-workflow-status-cli.d.mts +2 -0
- package/lib/github-workflows/get-latest-workflow-status-cli.mjs +61 -0
- package/lib/github-workflows/get-latest-workflow-status.cjs +56 -0
- package/lib/github-workflows/get-latest-workflow-status.d.mts +1 -0
- package/lib/github-workflows/get-latest-workflow-status.mjs +8 -0
- package/lib/github-workflows/utils.cjs +279 -0
- package/lib/github-workflows/utils.d.cts +76 -0
- package/lib/github-workflows/utils.mjs +8 -0
- package/lib/github-workflows/workflow-badge-cli.cjs +730 -0
- package/lib/github-workflows/workflow-badge-cli.d.mts +2 -0
- package/lib/github-workflows/workflow-badge-cli.mjs +98 -0
- package/lib/github-workflows/workflow-badge-generator.cjs +200 -0
- package/lib/github-workflows/workflow-badge-generator.d.mts +14 -0
- package/lib/github-workflows/workflow-badge-generator.mjs +8 -0
- package/lib/github-workflows/workflow-test-data.cjs +73 -0
- package/lib/github-workflows/workflow-test-data.d.cts +63 -0
- package/lib/github-workflows/workflow-test-data.mjs +6 -0
- package/lib/node-cache-cleaner-cli.mjs +3 -3
- package/lib/opencode/cli/auth-rotate.cjs +458 -0
- package/lib/opencode/cli/auth-rotate.d.ts +3 -0
- package/lib/opencode/cli/auth-rotate.js +65 -0
- package/lib/opencode/cli/auth-rotate.mjs +14 -0
- package/lib/opencode/cli/auth-rotate.runner.cjs +454 -0
- package/lib/opencode/cli/auth-rotate.runner.d.ts +1 -0
- package/lib/opencode/cli/auth-rotate.runner.js +8 -0
- package/lib/opencode/cli/auth-rotate.runner.mjs +21 -0
- package/lib/opencode/cli/list-projects.cjs +184 -0
- package/lib/opencode/cli/list-projects.d.ts +1 -0
- package/lib/opencode/cli/list-projects.js +32 -0
- package/lib/opencode/cli/list-projects.mjs +11 -0
- package/lib/opencode/cli/list-sessions.cjs +215 -0
- package/lib/opencode/cli/list-sessions.d.ts +1 -0
- package/lib/opencode/cli/list-sessions.js +45 -0
- package/lib/opencode/cli/list-sessions.mjs +11 -0
- package/lib/opencode/database.cjs +349 -0
- package/lib/opencode/database.d.ts +91 -0
- package/lib/opencode/database.js +252 -0
- package/lib/opencode/database.mjs +28 -0
- package/lib/opencode/database.runner.cjs +145 -0
- package/lib/opencode/database.runner.d.ts +1 -0
- package/lib/opencode/database.runner.js +56 -0
- package/lib/opencode/database.runner.mjs +37 -0
- package/lib/opencode/install-opencode-plugins-cli.cjs +82 -0
- package/lib/opencode/install-opencode-plugins-cli.d.ts +1 -0
- package/lib/opencode/install-opencode-plugins-cli.js +78 -0
- package/lib/opencode/install-opencode-plugins-cli.mjs +65 -0
- package/lib/opencode/opencode-zen.runner.cjs +48 -0
- package/lib/opencode/opencode-zen.runner.d.mts +1 -0
- package/lib/opencode/opencode-zen.runner.mjs +31 -0
- package/lib/opencode/sqlite.cjs +114 -0
- package/lib/opencode/sqlite.d.ts +18 -0
- package/lib/opencode/sqlite.js +82 -0
- package/lib/opencode/sqlite.mjs +10 -0
- package/lib/opencode/storage.cjs +124 -0
- package/lib/opencode/storage.d.ts +27 -0
- package/lib/opencode/storage.js +101 -0
- package/lib/opencode/storage.mjs +38 -0
- package/lib/opencode/storage.runner.cjs +50 -0
- package/lib/opencode/storage.runner.d.ts +1 -0
- package/lib/opencode/storage.runner.js +13 -0
- package/lib/opencode/storage.runner.mjs +29 -0
- package/lib/opencode/types.cjs +17 -0
- package/lib/opencode/types.d.ts +31 -0
- package/lib/opencode/types.js +2 -0
- package/lib/opencode/types.mjs +7 -0
- package/lib/opencode/utils/check-api.cjs +373 -0
- package/lib/opencode/utils/check-api.d.ts +16 -0
- package/lib/opencode/utils/check-api.js +132 -0
- package/lib/opencode/utils/check-api.mjs +12 -0
- package/lib/opencode/utils/check-api.runner.cjs +0 -0
- package/lib/opencode/utils/check-api.runner.d.ts +0 -0
- package/lib/opencode/utils/check-api.runner.js +1 -0
- package/lib/opencode/utils/check-api.runner.mjs +7 -0
- package/lib/opencode-cli.cjs +796 -0
- package/lib/opencode-cli.d.ts +2 -0
- package/lib/opencode-cli.js +116 -0
- package/lib/opencode-cli.mjs +116 -0
- package/lib/package-resolutions-updater-cli.cjs +189 -154
- package/lib/package-resolutions-updater-cli.mjs +3 -2
- package/lib/package-resolutions-updater.cjs +189 -154
- package/lib/package-resolutions-updater.d.mts +12 -3
- package/lib/package-resolutions-updater.mjs +3 -2
- package/lib/print-directory-tree.cjs +139 -3
- package/lib/print-directory-tree.mjs +6 -3
- package/lib/print-tarball-tree-cli.cjs +305 -0
- package/lib/print-tarball-tree-cli.d.mts +2 -0
- package/lib/print-tarball-tree-cli.mjs +54 -0
- package/lib/print-tarball-tree.cjs +43 -216
- package/lib/print-tarball-tree.d.mts +4 -1
- package/lib/print-tarball-tree.mjs +12 -66
- package/lib/rmpath-cli.cjs +139 -5
- package/lib/rmpath-cli.mjs +3 -1
- package/lib/rmpath.cjs +155 -11
- package/lib/rmpath.mjs +3 -1
- package/lib/run-by-checksum/hash.cjs +50 -56
- package/lib/run-by-checksum/hash.d.cts +24 -0
- package/lib/run-by-checksum/hash.mjs +3 -7
- package/lib/run-by-checksum/run.cjs +95 -42
- package/lib/run-by-checksum/run.js +3 -3
- package/lib/run-by-checksum/run.mjs +2 -2
- package/lib/run-by-checksum-cli.cjs +96 -58
- package/lib/run-by-checksum-cli.mjs +2 -2
- package/lib/submodule-install.cjs +138 -4
- package/lib/submodule-install.mjs +5 -4
- package/lib/submodule-remove-cli.cjs +139 -5
- package/lib/submodule-remove-cli.mjs +3 -1
- package/lib/submodule-remove.cjs +154 -5
- package/lib/submodule-remove.mjs +3 -1
- package/lib/utils/findEnvFiles.cjs +3 -0
- package/lib/utils/findEnvFiles.d.cts +2 -2
- package/lib/utils/findEnvFiles.mjs +1 -1
- package/lib/utils/isDebug.cjs +13 -0
- package/lib/utils/isDebug.d.cts +9 -0
- package/lib/utils/isDebug.mjs +6 -0
- package/lib/vscode/project.cjs +0 -0
- package/lib/vscode/project.d.ts +0 -0
- package/lib/vscode/project.js +1 -0
- package/lib/vscode/project.mjs +7 -0
- package/lib/vscode/storage.cjs +138 -0
- package/lib/vscode/storage.d.ts +51 -0
- package/lib/vscode/storage.js +169 -0
- package/lib/vscode/storage.mjs +42 -0
- package/lib/vscode/storage.runner.cjs +125 -0
- package/lib/vscode/storage.runner.d.ts +1 -0
- package/lib/vscode/storage.runner.js +47 -0
- package/lib/vscode/storage.runner.mjs +60 -0
- package/lib/vscode-cli.cjs +155 -0
- package/lib/vscode-cli.d.ts +2 -0
- package/lib/vscode-cli.js +80 -0
- package/lib/vscode-cli.mjs +71 -0
- package/package.json +50 -26
- package/readme.md +104 -8
- package/releases/readme.md +1 -1
- package/src/github-workflows/generate-test-ci-step-cli.mjs +126 -0
- package/vendor/clue/ndjson-react/README.md +365 -0
- package/vendor/composer/pcre/README.md +189 -0
- package/vendor/composer/semver/README.md +99 -0
- package/vendor/composer/xdebug-handler/README.md +305 -0
- package/vendor/ergebnis/agent-detector/README.md +107 -0
- package/vendor/evenement/evenement/README.md +64 -0
- package/vendor/fidry/cpu-core-counter/README.md +138 -0
- package/vendor/friendsofphp/php-cs-fixer/README.md +97 -0
- package/vendor/psr/container/README.md +13 -0
- package/vendor/psr/event-dispatcher/README.md +6 -0
- package/vendor/psr/log/README.md +58 -0
- package/vendor/react/cache/README.md +367 -0
- package/vendor/react/child-process/README.md +619 -0
- package/vendor/react/dns/README.md +453 -0
- package/vendor/react/event-loop/README.md +930 -0
- package/vendor/react/promise/README.md +722 -0
- package/vendor/react/socket/README.md +1564 -0
- package/vendor/react/stream/README.md +1249 -0
- package/vendor/sebastian/diff/README.md +151 -0
- package/vendor/symfony/console/README.md +30 -0
- package/vendor/symfony/deprecation-contracts/README.md +26 -0
- package/vendor/symfony/event-dispatcher/README.md +25 -0
- package/vendor/symfony/event-dispatcher-contracts/README.md +9 -0
- package/vendor/symfony/filesystem/README.md +23 -0
- package/vendor/symfony/finder/README.md +24 -0
- package/vendor/symfony/options-resolver/README.md +25 -0
- package/vendor/symfony/polyfill-ctype/README.md +12 -0
- package/vendor/symfony/polyfill-intl-grapheme/README.md +32 -0
- package/vendor/symfony/polyfill-intl-normalizer/README.md +14 -0
- package/vendor/symfony/polyfill-mbstring/README.md +13 -0
- package/vendor/symfony/polyfill-php80/README.md +25 -0
- package/vendor/symfony/polyfill-php81/README.md +18 -0
- package/vendor/symfony/polyfill-php84/README.md +23 -0
- package/vendor/symfony/polyfill-php85/README.md +20 -0
- package/vendor/symfony/process/README.md +23 -0
- package/vendor/symfony/service-contracts/README.md +9 -0
- package/vendor/symfony/stopwatch/README.md +52 -0
- package/vendor/symfony/string/README.md +24 -0
- package/lib/chunk-WSHVPGNM.mjs +0 -44
- package/lib/chunk-X2B3X7D4.mjs +0 -35
- package/lib/del-gradle.js +0 -16
- package/lib/del-node-modules.js +0 -211
- package/lib/find-node-modules-cli.js +0 -4
- package/lib/run-by-checksum/hash.d.ts +0 -14
- package/lib/run-by-checksum/hash.js +0 -85
- package/readme.html +0 -784
- /package/lib/{clean-github-actions-caches-cli.d.cts → del-gradle.d.cts} +0 -0
- /package/lib/{del-gradle.d.ts → del-node-modules.d.cts} +0 -0
- /package/lib/{find-node-modules-cli.d.ts → find-node-modules-cli.d.cts} +0 -0
- /package/lib/{git-diff-cli.d.ts → git/git-diff-cli.d.ts} +0 -0
- /package/lib/{git-diff-cli.js → git/git-diff-cli.js} +0 -0
- /package/lib/{git-diff.d.ts → git/git-diff.d.ts} +0 -0
- /package/lib/{git-fix.d.cts → git/git-fix.d.cts} +0 -0
- /package/lib/{git-purge.d.cts → git/git-purge.d.cts} +0 -0
- /package/lib/{del-node-modules.d.ts → github-workflows/clean-github-actions-caches-cli.d.cts} +0 -0
- /package/lib/{clean-github-actions-caches.d.cts → github-workflows/clean-github-actions-caches.d.cts} +0 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# composer/xdebug-handler
|
|
2
|
+
|
|
3
|
+
[](https://packagist.org/packages/composer/xdebug-handler)
|
|
4
|
+
[](https://github.com/composer/xdebug-handler/actions?query=branch:main)
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
Restart a CLI process without loading the Xdebug extension, unless `xdebug.mode=off`.
|
|
9
|
+
|
|
10
|
+
Originally written as part of [composer/composer](https://github.com/composer/composer),
|
|
11
|
+
now extracted and made available as a stand-alone library.
|
|
12
|
+
|
|
13
|
+
### Version 3
|
|
14
|
+
|
|
15
|
+
Removed support for legacy PHP versions and added type declarations.
|
|
16
|
+
|
|
17
|
+
Long term support for version 2 (PHP 5.3.2 - 7.2.4) follows [Composer 2.2 LTS](https://blog.packagist.com/composer-2-2/) policy.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Install the latest version with:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
$ composer require composer/xdebug-handler
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Requirements
|
|
28
|
+
|
|
29
|
+
* PHP 7.2.5 minimum, although using the latest PHP version is highly recommended.
|
|
30
|
+
|
|
31
|
+
## Basic Usage
|
|
32
|
+
```php
|
|
33
|
+
use Composer\XdebugHandler\XdebugHandler;
|
|
34
|
+
|
|
35
|
+
$xdebug = new XdebugHandler('myapp');
|
|
36
|
+
$xdebug->check();
|
|
37
|
+
unset($xdebug);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The constructor takes a single parameter, `$envPrefix`, which is upper-cased and prepended to default base values to create two distinct environment variables. The above example enables the use of:
|
|
41
|
+
|
|
42
|
+
- `MYAPP_ALLOW_XDEBUG=1` to override automatic restart and allow Xdebug
|
|
43
|
+
- `MYAPP_ORIGINAL_INIS` to obtain ini file locations in a restarted process
|
|
44
|
+
|
|
45
|
+
## Advanced Usage
|
|
46
|
+
|
|
47
|
+
* [How it works](#how-it-works)
|
|
48
|
+
* [Limitations](#limitations)
|
|
49
|
+
* [Helper methods](#helper-methods)
|
|
50
|
+
* [Setter methods](#setter-methods)
|
|
51
|
+
* [Process configuration](#process-configuration)
|
|
52
|
+
* [Troubleshooting](#troubleshooting)
|
|
53
|
+
* [Extending the library](#extending-the-library)
|
|
54
|
+
* [Examples](#examples)
|
|
55
|
+
|
|
56
|
+
### How it works
|
|
57
|
+
|
|
58
|
+
A temporary ini file is created from the loaded (and scanned) ini files, with any references to the Xdebug extension commented out. Current ini settings are merged, so that most ini settings made on the command-line or by the application are included (see [Limitations](#limitations))
|
|
59
|
+
|
|
60
|
+
* `MYAPP_ALLOW_XDEBUG` is set with internal data to flag and use in the restart.
|
|
61
|
+
* The command-line and environment are [configured](#process-configuration) for the restart.
|
|
62
|
+
* The application is restarted in a new process.
|
|
63
|
+
* The restart settings are stored in the environment.
|
|
64
|
+
* `MYAPP_ALLOW_XDEBUG` is unset.
|
|
65
|
+
* The application runs and exits.
|
|
66
|
+
* The main process exits with the exit code from the restarted process.
|
|
67
|
+
|
|
68
|
+
See [Examples](#examples) for further information.
|
|
69
|
+
|
|
70
|
+
#### Signal handling
|
|
71
|
+
Asynchronous signal handling is automatically enabled if the pcntl extension is loaded. `SIGINT` is set to `SIG_IGN` in the parent
|
|
72
|
+
process and restored to `SIG_DFL` in the restarted process (if no other handler has been set).
|
|
73
|
+
|
|
74
|
+
From PHP 7.4 on Windows, `CTRL+C` and `CTRL+BREAK` handling is automatically enabled in the restarted process and ignored in the parent process.
|
|
75
|
+
|
|
76
|
+
### Limitations
|
|
77
|
+
There are a few things to be aware of when running inside a restarted process.
|
|
78
|
+
|
|
79
|
+
* Extensions set on the command-line will not be loaded.
|
|
80
|
+
* Ini file locations will be reported as per the restart - see [getAllIniFiles()](#getallinifiles-array).
|
|
81
|
+
* Php sub-processes may be loaded with Xdebug enabled - see [Process configuration](#process-configuration).
|
|
82
|
+
|
|
83
|
+
### Helper methods
|
|
84
|
+
These static methods provide information from the current process, regardless of whether it has been restarted or not.
|
|
85
|
+
|
|
86
|
+
#### _getAllIniFiles(): array_
|
|
87
|
+
Returns an array of the original ini file locations. Use this instead of calling `php_ini_loaded_file` and `php_ini_scanned_files`, which will report the wrong values in a restarted process.
|
|
88
|
+
|
|
89
|
+
```php
|
|
90
|
+
use Composer\XdebugHandler\XdebugHandler;
|
|
91
|
+
|
|
92
|
+
$files = XdebugHandler::getAllIniFiles();
|
|
93
|
+
|
|
94
|
+
# $files[0] always exists, it could be an empty string
|
|
95
|
+
$loadedIni = array_shift($files);
|
|
96
|
+
$scannedInis = $files;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
These locations are also available in the `MYAPP_ORIGINAL_INIS` environment variable. This is a path-separated string comprising the location returned from `php_ini_loaded_file`, which could be empty, followed by locations parsed from calling `php_ini_scanned_files`.
|
|
100
|
+
|
|
101
|
+
#### _getRestartSettings(): ?array_
|
|
102
|
+
Returns an array of settings that can be used with PHP [sub-processes](#sub-processes), or null if the process was not restarted.
|
|
103
|
+
|
|
104
|
+
```php
|
|
105
|
+
use Composer\XdebugHandler\XdebugHandler;
|
|
106
|
+
|
|
107
|
+
$settings = XdebugHandler::getRestartSettings();
|
|
108
|
+
/**
|
|
109
|
+
* $settings: array (if the current process was restarted,
|
|
110
|
+
* or called with the settings from a previous restart), or null
|
|
111
|
+
*
|
|
112
|
+
* 'tmpIni' => the temporary ini file used in the restart (string)
|
|
113
|
+
* 'scannedInis' => if there were any scanned inis (bool)
|
|
114
|
+
* 'scanDir' => the original PHP_INI_SCAN_DIR value (false|string)
|
|
115
|
+
* 'phprc' => the original PHPRC value (false|string)
|
|
116
|
+
* 'inis' => the original inis from getAllIniFiles (array)
|
|
117
|
+
* 'skipped' => the skipped version from getSkippedVersion (string)
|
|
118
|
+
*/
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### _getSkippedVersion(): string_
|
|
122
|
+
Returns the Xdebug version string that was skipped by the restart, or an empty string if there was no restart (or Xdebug is still loaded, perhaps by an extending class restarting for a reason other than removing Xdebug).
|
|
123
|
+
|
|
124
|
+
```php
|
|
125
|
+
use Composer\XdebugHandler\XdebugHandler;
|
|
126
|
+
|
|
127
|
+
$version = XdebugHandler::getSkippedVersion();
|
|
128
|
+
# $version: '3.1.1' (for example), or an empty string
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### _isXdebugActive(): bool_
|
|
132
|
+
Returns true if Xdebug is loaded and is running in an active mode (if it supports modes). Returns false if Xdebug is not loaded, or it is running with `xdebug.mode=off`.
|
|
133
|
+
|
|
134
|
+
### Setter methods
|
|
135
|
+
These methods implement a fluent interface and must be called before the main `check()` method.
|
|
136
|
+
|
|
137
|
+
#### _setLogger(LoggerInterface $logger): self_
|
|
138
|
+
Enables the output of status messages to an external PSR3 logger. All messages are reported with either `DEBUG` or `WARNING` log levels. For example (showing the level and message):
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
// No restart
|
|
142
|
+
DEBUG Checking MYAPP_ALLOW_XDEBUG
|
|
143
|
+
DEBUG The Xdebug extension is loaded (3.1.1) xdebug.mode=off
|
|
144
|
+
DEBUG No restart (APP_ALLOW_XDEBUG=0) Allowed by xdebug.mode
|
|
145
|
+
|
|
146
|
+
// Restart overridden
|
|
147
|
+
DEBUG Checking MYAPP_ALLOW_XDEBUG
|
|
148
|
+
DEBUG The Xdebug extension is loaded (3.1.1) xdebug.mode=coverage,debug,develop
|
|
149
|
+
DEBUG No restart (MYAPP_ALLOW_XDEBUG=1)
|
|
150
|
+
|
|
151
|
+
// Failed restart
|
|
152
|
+
DEBUG Checking MYAPP_ALLOW_XDEBUG
|
|
153
|
+
DEBUG The Xdebug extension is loaded (3.1.0)
|
|
154
|
+
WARNING No restart (Unable to create temp ini file at: ...)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Status messages can also be output with `XDEBUG_HANDLER_DEBUG`. See [Troubleshooting](#troubleshooting).
|
|
158
|
+
|
|
159
|
+
#### _setMainScript(string $script): self_
|
|
160
|
+
Sets the location of the main script to run in the restart. This is only needed in more esoteric use-cases, or if the `argv[0]` location is inaccessible. The script name `--` is supported for standard input.
|
|
161
|
+
|
|
162
|
+
#### _setPersistent(): self_
|
|
163
|
+
Configures the restart using [persistent settings](#persistent-settings), so that Xdebug is not loaded in any sub-process.
|
|
164
|
+
|
|
165
|
+
Use this method if your application invokes one or more PHP sub-process and the Xdebug extension is not needed. This avoids the overhead of implementing specific [sub-process](#sub-processes) strategies.
|
|
166
|
+
|
|
167
|
+
Alternatively, this method can be used to set up a default _Xdebug-free_ environment which can be changed if a sub-process requires Xdebug, then restored afterwards:
|
|
168
|
+
|
|
169
|
+
```php
|
|
170
|
+
function SubProcessWithXdebug()
|
|
171
|
+
{
|
|
172
|
+
$phpConfig = new Composer\XdebugHandler\PhpConfig();
|
|
173
|
+
|
|
174
|
+
# Set the environment to the original configuration
|
|
175
|
+
$phpConfig->useOriginal();
|
|
176
|
+
|
|
177
|
+
# run the process with Xdebug loaded
|
|
178
|
+
...
|
|
179
|
+
|
|
180
|
+
# Restore Xdebug-free environment
|
|
181
|
+
$phpConfig->usePersistent();
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Process configuration
|
|
186
|
+
The library offers two strategies to invoke a new PHP process without loading Xdebug, using either _standard_ or _persistent_ settings. Note that this is only important if the application calls a PHP sub-process.
|
|
187
|
+
|
|
188
|
+
#### Standard settings
|
|
189
|
+
Uses command-line options to remove Xdebug from the new process only.
|
|
190
|
+
|
|
191
|
+
* The -n option is added to the command-line. This tells PHP not to scan for additional inis.
|
|
192
|
+
* The temporary ini is added to the command-line with the -c option.
|
|
193
|
+
|
|
194
|
+
>_If the new process calls a PHP sub-process, Xdebug will be loaded in that sub-process (unless it implements xdebug-handler, in which case there will be another restart)._
|
|
195
|
+
|
|
196
|
+
This is the default strategy used in the restart.
|
|
197
|
+
|
|
198
|
+
#### Persistent settings
|
|
199
|
+
Uses environment variables to remove Xdebug from the new process and persist these settings to any sub-process.
|
|
200
|
+
|
|
201
|
+
* `PHP_INI_SCAN_DIR` is set to an empty string. This tells PHP not to scan for additional inis.
|
|
202
|
+
* `PHPRC` is set to the temporary ini.
|
|
203
|
+
|
|
204
|
+
>_If the new process calls a PHP sub-process, Xdebug will not be loaded in that sub-process._
|
|
205
|
+
|
|
206
|
+
This strategy can be used in the restart by calling [setPersistent()](#setpersistent-self).
|
|
207
|
+
|
|
208
|
+
#### Sub-processes
|
|
209
|
+
The `PhpConfig` helper class makes it easy to invoke a PHP sub-process (with or without Xdebug loaded), regardless of whether there has been a restart.
|
|
210
|
+
|
|
211
|
+
Each of its methods returns an array of PHP options (to add to the command-line) and sets up the environment for the required strategy. The [getRestartSettings()](#getrestartsettings-array) method is used internally.
|
|
212
|
+
|
|
213
|
+
* `useOriginal()` - Xdebug will be loaded in the new process.
|
|
214
|
+
* `useStandard()` - Xdebug will **not** be loaded in the new process - see [standard settings](#standard-settings).
|
|
215
|
+
* `userPersistent()` - Xdebug will **not** be loaded in the new process - see [persistent settings](#persistent-settings)
|
|
216
|
+
|
|
217
|
+
If there was no restart, an empty options array is returned and the environment is not changed.
|
|
218
|
+
|
|
219
|
+
```php
|
|
220
|
+
use Composer\XdebugHandler\PhpConfig;
|
|
221
|
+
|
|
222
|
+
$config = new PhpConfig;
|
|
223
|
+
|
|
224
|
+
$options = $config->useOriginal();
|
|
225
|
+
# $options: empty array
|
|
226
|
+
# environment: PHPRC and PHP_INI_SCAN_DIR set to original values
|
|
227
|
+
|
|
228
|
+
$options = $config->useStandard();
|
|
229
|
+
# $options: [-n, -c, tmpIni]
|
|
230
|
+
# environment: PHPRC and PHP_INI_SCAN_DIR set to original values
|
|
231
|
+
|
|
232
|
+
$options = $config->usePersistent();
|
|
233
|
+
# $options: empty array
|
|
234
|
+
# environment: PHPRC=tmpIni, PHP_INI_SCAN_DIR=''
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Troubleshooting
|
|
238
|
+
The following environment settings can be used to troubleshoot unexpected behavior:
|
|
239
|
+
|
|
240
|
+
* `XDEBUG_HANDLER_DEBUG=1` Outputs status messages to `STDERR`, if it is defined, irrespective of any PSR3 logger. Each message is prefixed `xdebug-handler[pid]`, where pid is the process identifier.
|
|
241
|
+
|
|
242
|
+
* `XDEBUG_HANDLER_DEBUG=2` As above, but additionally saves the temporary ini file and reports its location in a status message.
|
|
243
|
+
|
|
244
|
+
### Extending the library
|
|
245
|
+
The API is defined by classes and their accessible elements that are not annotated as @internal. The main class has two protected methods that can be overridden to provide additional functionality:
|
|
246
|
+
|
|
247
|
+
#### _requiresRestart(bool $default): bool_
|
|
248
|
+
By default the process will restart if Xdebug is loaded and not running with `xdebug.mode=off`. Extending this method allows an application to decide, by returning a boolean (or equivalent) value.
|
|
249
|
+
It is only called if `MYAPP_ALLOW_XDEBUG` is empty, so it will not be called in the restarted process (where this variable contains internal data), or if the restart has been overridden.
|
|
250
|
+
|
|
251
|
+
Note that the [setMainScript()](#setmainscriptstring-script-self) and [setPersistent()](#setpersistent-self) setters can be used here, if required.
|
|
252
|
+
|
|
253
|
+
#### _restart(array $command): void_
|
|
254
|
+
An application can extend this to modify the temporary ini file, its location given in the `tmpIni` property. New settings can be safely appended to the end of the data, which is `PHP_EOL` terminated.
|
|
255
|
+
|
|
256
|
+
The `$command` parameter is an array of unescaped command-line arguments that will be used for the new process.
|
|
257
|
+
|
|
258
|
+
Remember to finish with `parent::restart($command)`.
|
|
259
|
+
|
|
260
|
+
#### Example
|
|
261
|
+
This example demonstrates two ways to extend basic functionality:
|
|
262
|
+
|
|
263
|
+
* To avoid the overhead of spinning up a new process, the restart is skipped if a simple help command is requested.
|
|
264
|
+
|
|
265
|
+
* The application needs write-access to phar files, so it will force a restart if `phar.readonly` is set (regardless of whether Xdebug is loaded) and change this value in the temporary ini file.
|
|
266
|
+
|
|
267
|
+
```php
|
|
268
|
+
use Composer\XdebugHandler\XdebugHandler;
|
|
269
|
+
use MyApp\Command;
|
|
270
|
+
|
|
271
|
+
class MyRestarter extends XdebugHandler
|
|
272
|
+
{
|
|
273
|
+
private $required;
|
|
274
|
+
|
|
275
|
+
protected function requiresRestart(bool $default): bool
|
|
276
|
+
{
|
|
277
|
+
if (Command::isHelp()) {
|
|
278
|
+
# No need to disable Xdebug for this
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
$this->required = (bool) ini_get('phar.readonly');
|
|
283
|
+
return $this->required || $default;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
protected function restart(array $command): void
|
|
287
|
+
{
|
|
288
|
+
if ($this->required) {
|
|
289
|
+
# Add required ini setting to tmpIni
|
|
290
|
+
$content = file_get_contents($this->tmpIni);
|
|
291
|
+
$content .= 'phar.readonly=0'.PHP_EOL;
|
|
292
|
+
file_put_contents($this->tmpIni, $content);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
parent::restart($command);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Examples
|
|
301
|
+
The `tests\App` directory contains command-line scripts that demonstrate the internal workings in a variety of scenarios.
|
|
302
|
+
See [Functional Test Scripts](./tests/App/README.md).
|
|
303
|
+
|
|
304
|
+
## License
|
|
305
|
+
composer/xdebug-handler is licensed under the MIT License, see the LICENSE file for details.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# agent-detector
|
|
2
|
+
|
|
3
|
+
[](https://github.com/ergebnis/agent-detector/actions/workflows/integrate.yaml)
|
|
4
|
+
[](https://github.com/ergebnis/agent-detector/actions/workflows/merge.yaml)
|
|
5
|
+
[](https://github.com/ergebnis/agent-detector/actions/workflows/release.yaml)
|
|
6
|
+
[](https://github.com/ergebnis/agent-detector/actions/workflows/renew.yaml)
|
|
7
|
+
|
|
8
|
+
[](https://codecov.io/gh/ergebnis/agent-detector)
|
|
9
|
+
|
|
10
|
+
[](https://packagist.org/packages/ergebnis/agent-detector)
|
|
11
|
+
[](https://packagist.org/packages/ergebnis/agent-detector)
|
|
12
|
+
[](https://packagist.org/packages/ergebnis/agent-detector)
|
|
13
|
+
|
|
14
|
+
This project provides a [`composer`](https://getcomposer.org) package with a detector for detecting the presence of an agent.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Run
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
composer require ergebnis/agent-detector
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Detecting the presence of an agent
|
|
27
|
+
|
|
28
|
+
```php
|
|
29
|
+
<?php
|
|
30
|
+
|
|
31
|
+
declare(strict_types=1);
|
|
32
|
+
|
|
33
|
+
use Ergebnis\AgentDetector;
|
|
34
|
+
|
|
35
|
+
$detector = new AgentDetector\Detector();
|
|
36
|
+
|
|
37
|
+
$isAgentPresent = $detector->isAgentPresent(\getenv());
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Supported agents
|
|
41
|
+
|
|
42
|
+
This package detects the presence of the following agents via environment variables:
|
|
43
|
+
|
|
44
|
+
| Agent | Environment Variable |
|
|
45
|
+
|---|---|
|
|
46
|
+
| [Amp](https://amp.dev) | `AMP_CURRENT_THREAD_ID` |
|
|
47
|
+
| [Antigravity](https://antigravity.dev) | `ANTIGRAVITY_AGENT` |
|
|
48
|
+
| [Augment](https://augmentcode.com) | `AUGMENT_AGENT` |
|
|
49
|
+
| [Claude Code](https://github.com/anthropics/claude-code) | `CLAUDECODE`, `CLAUDE_CODE`, `CLAUDE_CODE_IS_COWORK` |
|
|
50
|
+
| [Codex](https://github.com/openai/codex) | `CODEX_CI`, `CODEX_SANDBOX`, `CODEX_THREAD_ID` |
|
|
51
|
+
| [Cursor](https://cursor.com) | `CURSOR_AGENT`, `CURSOR_EXTENSION_HOST_ROLE`, `CURSOR_TRACE_ID` |
|
|
52
|
+
| [Gemini CLI](https://github.com/google-gemini/gemini-cli) | `GEMINI_CLI` |
|
|
53
|
+
| [GitHub Copilot](https://github.com/features/copilot) | `COPILOT_ALLOW_ALL`, `COPILOT_CLI`, `COPILOT_GITHUB_TOKEN`, `COPILOT_MODEL |
|
|
54
|
+
| [OpenCode](https://github.com/sst/opencode) | `OPENCODE`, `OPENCODE_CLIENT` |
|
|
55
|
+
| [Pi](https://pi.dev) | `PI_CODING_AGENT` |
|
|
56
|
+
| [Replit](https://replit.com) | `REPL_ID` |
|
|
57
|
+
|
|
58
|
+
### Indicating the presence of an agent
|
|
59
|
+
|
|
60
|
+
In addition, the generic `AI_AGENT` environment variable can be set to indicate the presence of an agent.
|
|
61
|
+
|
|
62
|
+
## Changelog
|
|
63
|
+
|
|
64
|
+
The maintainers of this project record notable changes to this project in a [changelog](CHANGELOG.md).
|
|
65
|
+
|
|
66
|
+
## Contributing
|
|
67
|
+
|
|
68
|
+
The maintainers of this project suggest following the [contribution guide](.github/CONTRIBUTING.md).
|
|
69
|
+
|
|
70
|
+
## Code of Conduct
|
|
71
|
+
|
|
72
|
+
The maintainers of this project ask contributors to follow the [code of conduct](https://github.com/ergebnis/.github/blob/main/CODE_OF_CONDUCT.md).
|
|
73
|
+
|
|
74
|
+
## General Support Policy
|
|
75
|
+
|
|
76
|
+
The maintainers of this project provide limited support.
|
|
77
|
+
|
|
78
|
+
## PHP Version Support Policy
|
|
79
|
+
|
|
80
|
+
This project currently supports the following PHP versions:
|
|
81
|
+
|
|
82
|
+
- [PHP 7.4](https://www.php.net/releases/#7.4.0) (has reached its end of life on November 28, 2022)
|
|
83
|
+
- [PHP 8.0](https://www.php.net/releases/#8.0.0) (has reached its end of life on November 26, 2023)
|
|
84
|
+
- [PHP 8.1](https://www.php.net/releases/#8.1.0) (has reached its end of life on December 31, 2025)
|
|
85
|
+
- [PHP 8.2](https://www.php.net/releases/#8.2.0)
|
|
86
|
+
- [PHP 8.3](https://www.php.net/releases/#8.3.0)
|
|
87
|
+
- [PHP 8.4](https://www.php.net/releases/#8.4.0)
|
|
88
|
+
- [PHP 8.5](https://www.php.net/releases/#8.5.0)
|
|
89
|
+
|
|
90
|
+
The maintainers of this project add support for a PHP version following its initial release and _may_ drop support for a PHP version when it has reached its [end of life](https://www.php.net/supported-versions.php).
|
|
91
|
+
|
|
92
|
+
## Security Policy
|
|
93
|
+
|
|
94
|
+
This project has a [security policy](.github/SECURITY.md).
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
This project uses the [MIT license](LICENSE.md).
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## Credits
|
|
102
|
+
|
|
103
|
+
The agent detector is inspired by [`shipfastlabs/agent-detector`](https://github.com/shipfastlabs/agent-detector), originally licensed under MIT by [Pushpak Chhajed](https://github.com/pushpak1300).
|
|
104
|
+
|
|
105
|
+
## Social
|
|
106
|
+
|
|
107
|
+
Follow [@localheinz](https://twitter.com/intent/follow?screen_name=localheinz) and [@ergebnis](https://twitter.com/intent/follow?screen_name=ergebnis) on Twitter.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Événement
|
|
2
|
+
|
|
3
|
+
Événement is a very simple event dispatching library for PHP.
|
|
4
|
+
|
|
5
|
+
It has the same design goals as [Silex](https://silex.symfony.com/) and
|
|
6
|
+
[Pimple](https://github.com/silexphp/Pimple), to empower the user while staying concise
|
|
7
|
+
and simple.
|
|
8
|
+
|
|
9
|
+
It is very strongly inspired by the [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter) API found in
|
|
10
|
+
[node.js](http://nodejs.org).
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+
[](https://packagist.org/packages/evenement/evenement)
|
|
14
|
+
[](https://packagist.org/packages/evenement/evenement/stats)
|
|
15
|
+
[](https://packagist.org/packages/evenement/evenement)
|
|
16
|
+
|
|
17
|
+
## Fetch
|
|
18
|
+
|
|
19
|
+
The recommended way to install Événement is [through composer](http://getcomposer.org). By running the following command:
|
|
20
|
+
|
|
21
|
+
$ composer require evenement/evenement
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Creating an Emitter
|
|
26
|
+
|
|
27
|
+
```php
|
|
28
|
+
<?php
|
|
29
|
+
$emitter = new Evenement\EventEmitter();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Adding Listeners
|
|
33
|
+
|
|
34
|
+
```php
|
|
35
|
+
<?php
|
|
36
|
+
$emitter->on('user.created', function (User $user) use ($logger) {
|
|
37
|
+
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Removing Listeners
|
|
42
|
+
|
|
43
|
+
```php
|
|
44
|
+
<?php
|
|
45
|
+
$emitter->removeListener('user.created', function (User $user) use ($logger) {
|
|
46
|
+
$logger->log(sprintf("User '%s' was created.", $user->getLogin()));
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Emitting Events
|
|
51
|
+
|
|
52
|
+
```php
|
|
53
|
+
<?php
|
|
54
|
+
$emitter->emit('user.created', [$user]);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Tests
|
|
58
|
+
-----
|
|
59
|
+
|
|
60
|
+
$ ./vendor/bin/phpunit
|
|
61
|
+
|
|
62
|
+
License
|
|
63
|
+
-------
|
|
64
|
+
MIT, see LICENSE.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# CPU Core Counter
|
|
2
|
+
|
|
3
|
+
This package is a tiny utility to get the number of CPU cores.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
composer require fidry/cpu-core-counter
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```php
|
|
13
|
+
use Fidry\CpuCoreCounter\CpuCoreCounter;
|
|
14
|
+
use Fidry\CpuCoreCounter\NumberOfCpuCoreNotFound;
|
|
15
|
+
use Fidry\CpuCoreCounter\Finder\DummyCpuCoreFinder;
|
|
16
|
+
|
|
17
|
+
$counter = new CpuCoreCounter();
|
|
18
|
+
|
|
19
|
+
// For knowing the number of cores you can use for launching parallel processes:
|
|
20
|
+
$counter->getAvailableForParallelisation()->availableCpus;
|
|
21
|
+
|
|
22
|
+
// Get the number of CPU cores (by default it will use the logical cores count):
|
|
23
|
+
try {
|
|
24
|
+
$counter->getCount(); // e.g. 8
|
|
25
|
+
} catch (NumberOfCpuCoreNotFound) {
|
|
26
|
+
return 1; // Fallback value
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// An alternative form where we not want to catch the exception:
|
|
30
|
+
|
|
31
|
+
$counter = new CpuCoreCounter([
|
|
32
|
+
...CpuCoreCounter::getDefaultFinders(),
|
|
33
|
+
new DummyCpuCoreFinder(1), // Fallback value
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
// A type-safe alternative form:
|
|
37
|
+
$counter->getCountWithFallback(1);
|
|
38
|
+
|
|
39
|
+
// Note that the result is memoized.
|
|
40
|
+
$counter->getCount(); // e.g. 8
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Advanced usage
|
|
46
|
+
|
|
47
|
+
### Changing the finders
|
|
48
|
+
|
|
49
|
+
When creating `CpuCoreCounter`, you may want to change the order of the finders
|
|
50
|
+
used or disable a specific finder. You can easily do so by passing the finders
|
|
51
|
+
you want
|
|
52
|
+
|
|
53
|
+
```php
|
|
54
|
+
// Remove WindowsWmicFinder
|
|
55
|
+
$finders = array_filter(
|
|
56
|
+
CpuCoreCounter::getDefaultFinders(),
|
|
57
|
+
static fn (CpuCoreFinder $finder) => !($finder instanceof WindowsWmicFinder)
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
$cores = (new CpuCoreCounter($finders))->getCount();
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```php
|
|
64
|
+
// Use CPUInfo first & don't use Nproc
|
|
65
|
+
$finders = [
|
|
66
|
+
new CpuInfoFinder(),
|
|
67
|
+
new WindowsWmicFinder(),
|
|
68
|
+
new HwLogicalFinder(),
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
$cores = (new CpuCoreCounter($finders))->getCount();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Choosing only logical or physical finders
|
|
75
|
+
|
|
76
|
+
`FinderRegistry` provides two helpful entries:
|
|
77
|
+
|
|
78
|
+
- `::getDefaultLogicalFinders()`: gives an ordered list of finders that will
|
|
79
|
+
look for the _logical_ CPU cores count.
|
|
80
|
+
- `::getDefaultPhysicalFinders()`: gives an ordered list of finders that will
|
|
81
|
+
look for the _physical_ CPU cores count.
|
|
82
|
+
|
|
83
|
+
By default, when using `CpuCoreCounter`, it will use the logical finders since
|
|
84
|
+
it is more likely what you are looking for and is what is used by PHP source to
|
|
85
|
+
build the PHP binary.
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
### Checks what finders find what on your system
|
|
89
|
+
|
|
90
|
+
You have three scrips available that provides insight about what the finders
|
|
91
|
+
can find:
|
|
92
|
+
|
|
93
|
+
```shell
|
|
94
|
+
# Checks what each given finder will find on your system with details about the
|
|
95
|
+
# information it had.
|
|
96
|
+
make diagnose # From this repository
|
|
97
|
+
./vendor/fidry/cpu-core-counter/bin/diagnose.php # From the library
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
And:
|
|
101
|
+
```shell
|
|
102
|
+
# Execute all finders and display the result they found.
|
|
103
|
+
make execute # From this repository
|
|
104
|
+
./vendor/fidry/cpu-core-counter/bin/execute.php # From the library
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
### Debug the results found
|
|
109
|
+
|
|
110
|
+
You have 3 methods available to help you find out what happened:
|
|
111
|
+
|
|
112
|
+
1. If you are using the default configuration of finder registries, you can check
|
|
113
|
+
the previous section which will provide plenty of information.
|
|
114
|
+
2. If what you are interested in is how many CPU cores were found, you can use
|
|
115
|
+
the `CpuCoreCounter::trace()` method.
|
|
116
|
+
3. If what you are interested in is how the calculation of CPU cores available
|
|
117
|
+
for parallelisation was done, you can inspect the values of `ParallelisationResult`
|
|
118
|
+
returned by `CpuCoreCounter::getAvailableForParallelisation()`.
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Backward Compatibility Promise (BCP)
|
|
122
|
+
|
|
123
|
+
The policy is for the major part following the same as [Symfony's one][symfony-bc-policy].
|
|
124
|
+
Note that the code marked as `@private` or `@internal` are excluded from the BCP.
|
|
125
|
+
|
|
126
|
+
The following elements are also excluded:
|
|
127
|
+
|
|
128
|
+
- The `diagnose` and `execute` commands: those are for debugging/inspection purposes only
|
|
129
|
+
- `FinderRegistry::get*Finders()`: new finders may be added or the order of finders changed at any time
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
This package is licensed using the MIT License.
|
|
135
|
+
|
|
136
|
+
Please have a look at [`LICENSE.md`](LICENSE.md).
|
|
137
|
+
|
|
138
|
+
[symfony-bc-policy]: https://symfony.com/doc/current/contributing/code/bc.html
|