Getting started
Installation
Add the compiler to a Composer project, configure it, and run the generated PHP.Requirements
- PHP 8.4 or newer and Composer 2 on the machine that runs the compiler
- A Composer project with its source beneath the project root
- An output directory that does not overlap any source directory
The compiler is a development dependency. Your application runs the generated PHP tree on whatever PHP version that tree targets (see targetPhpVersion in Project configuration); the compiler itself is not needed in production.
Native compiler commands allow at least 512 MiB by default, preserving a higher or unlimited PHP allowance. To choose a different limit, set PPPHP_COMPILER_MEMORY_LIMIT_MEGABYTES in your shell or CI environment:
export PPPHP_COMPILER_MEMORY_LIMIT_MEGABYTES=768
Choose an allowance that fits your source and Composer dependency graph. This setting affects compiler processes without changing your php.ini.
Install the compiler
composer require --dev atatusoft/ppphp
vendor/bin/ppphp --version
Composer selects Stable releases by default. The version command prints the exact release you have, which is worth including in any bug report.
Installing a release candidate
To evaluate a specific release candidate, use the exact installation command in its release notes. Keep the candidate constraint exact so Composer installs the build you intended to test.
Moving to the new package name
If your project still requires atatusoft-ltd/ppphp-src, switch to atatusoft/ppphp. Remove the old root requirement without updating dependencies, then add the current package:
composer remove --dev --no-update atatusoft-ltd/ppphp-src
composer require --dev atatusoft/ppphp
If the old package is in require rather than require-dev, omit --dev from the removal command. The new compiler remains a development dependency. For a release candidate, use the exact command from that release's notes instead of the unversioned second command. Do not leave both names in your root requirements.
Review and commit composer.json and composer.lock together after Composer succeeds. The CLI remains ppphp, PHP namespaces remain Atatusoft\Ppphp, and the source repository, release assets, and existing schema URLs keep their current locations. Published releases retain the package name they shipped with.
Initialize the project
Run the initializer from the project root:
vendor/bin/ppphp init
It creates ppphp.json, build/ppphp, .ppphp-cache, and stubs. Keep the generated targetPhpVersion and, when present, $schema values: they match the installed compiler and your project's PHP target. The configuration reference explains how Composer's PHP platform setting participates in target selection.
For the new example project below, create its source directory before configuring Composer:
mkdir -p src
In an existing project, set source in ppphp.json to the actual source directories you want to compile. Each configured source directory must exist before you run composer:configure, check, or build; init creates the managed output, cache, and stub directories without creating application source.
The schema URL is tied to the release that wrote it. Editors use it to validate and complete the file. Ordinary ppphp commands use bundled validation rules without fetching the schema, so checking and building stay local.
All configured paths are relative to the project root. Output and cache paths may not overlap source, and the compiler rejects unsafe paths instead of risking source data.
See Project configuration for every field, multi-root layouts, stubs, exclusions, custom paths, and the complete Composer metadata contract.
Set up Composer to load the build
Your root composer.json should describe the source namespace you own. For example:
{
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
Run composer:configure to change the autoload path from your source directory to the generated PHP directory. It saves the original source mapping under extra.ppphp for future checks and builds. Preview the change before applying it:
vendor/bin/ppphp composer:configure --dry-run
vendor/bin/ppphp composer:configure
composer update --lock --no-interaction --no-scripts
Review the Composer diff before committing it. Do not map the same namespace to both .ppphp source and emitted PHP as competing runtime definitions.
Build one working program
Create src/Greeting.ppphp:
<?php
namespace App;
final class Greeting
{
public function __construct(
public readonly string $name,
) {}
public string $message {
get => 'Hello, ' . $this->name;
}
}
Create src/index.php as the ordinary PHP entrypoint:
<?php
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
echo new App\Greeting('World')->message, "\n";
Check the project without replacing generated output, then build the complete tree:
vendor/bin/ppphp check
vendor/bin/ppphp build
composer dump-autoload --optimize
php -l build/ppphp/Greeting.php
php build/ppphp/index.php
The generated App\Greeting class is loaded through the projected PSR-4 mapping. The entrypoint is copied to build/ppphp/index.php, so it walks up two directories to load the project-root Composer installation. The final command prints Hello, World. .ppphp files are never executed directly; the generated tree is what runs. A complete build compiles selected .ppphp files, copies selected .php files byte-for-byte, validates the result, and atomically replaces build/ppphp only after the build succeeds.
Put the same workflow in CI
CI should install from composer.lock, print the compiler version for the log, check the complete project, build, refresh autoload metadata, and run the application test suite:
composer install --no-interaction --prefer-dist
vendor/bin/ppphp --version
vendor/bin/ppphp check --format=json
vendor/bin/ppphp build
composer dump-autoload --classmap-authoritative
vendor/bin/phpunit
Deploy the generated application tree together with the root Composer metadata and installed production dependencies. The compiler remains a development dependency and does not add a service or extension to production.
If you download release assets such as the schema or manifest directly, verify them against the published checksums first. See Verify downloads.
Continue with Project configuration for the full metadata reference, The CLI for selection and diagnostics, or Migrating from PHP for a file-by-file adoption plan.