The worker¶
Mago runs extension plugins in PHP child processes called workers. This page describes the bundled worker entry points, PHP runtime flags, protocol handling, and startup diagnostics.
Worker entry points¶
The package ships two equivalent entry points:
vendor/friendsofmago/mago-symfony/resources/worker.phpvendor/bin/mago-symfony-worker, a thin wrapper that requiresresources/worker.php
Register resources/worker.php under [extension-hosts.symfony] in mago.toml:
[extension-hosts.symfony]
command = ["php", "-d", "xdebug.mode=off", "-d", "pcov.enabled=0", "-d", "memory_limit=512M", "vendor/friendsofmago/mago-symfony/resources/worker.php"]
workers = 1
PHP runtime flags¶
-d xdebug.mode=offdisables Xdebug in the worker. PHP ignores the flag when Xdebug is not installed.-d pcov.enabled=0disables PCOV in the worker. PHP ignores the flag when PCOV is not installed.-d memory_limit=512Mraises the worker memory limit for large codebases and large compiled container XML dumps. Small and medium applications run within PHP's default128Mlimit.workers = 1runs one PHP worker process for this extension host.
To debug a provider with Xdebug, override XDEBUG_MODE in the shell because the environment variable takes precedence over -d xdebug.mode=off:
XDEBUG_MODE=debug vendor/bin/mago analyze
Protocol and stream separation¶
Mago communicates with the worker over standard input and standard output using binary frames. Any stray text written to standard output breaks framing.
resources/worker.php protects the stream before loading Composer's autoloader:
- Sets
display_errorstostderr. - Starts an output buffer callback that redirects printed output to standard error.
- Catches any
Throwableraised during autoloading or worker execution, writes the message to standard error, flushes the stream, and exits with code1.
Autoloader discovery¶
resources/worker.php searches these candidate paths for Composer's autoload.php:
$GLOBALS['_composer_autoload_path'], set when invoked through Composer's bin proxy.dirname(__DIR__, 3) . '/autoload.php', when installed undervendor/friendsofmago/mago-symfony/.dirname($_SERVER['SCRIPT_FILENAME'], 2) . '/autoload.php'anddirname($_SERVER['SCRIPT_FILENAME'], 4) . '/autoload.php'.getcwd() . '/vendor/autoload.php'.dirname(__DIR__) . '/vendor/autoload.php', in a package checkout root.
The worker accepts an autoloader only when its composer/autoload_psr4.php maps MagoSymfony\ to the same realpath as the running package's src/ directory. That guard prevents a symlinked path repository from loading a stale copy of the package.
Configuration errors and warnings¶
- Missing auto-discovered paths. If
.mago/symfony-container.json,var/cache/dev/*Container.xml, andvar/cache/test/*Container.xmldo not exist, startup stays silent and succeeds. - Explicit container errors. If
MAGO_SYMFONY_CONTAINER_XMLorMAGO_SYMFONY_CONTAINER_MAPpoints to a missing, unreadable, or malformed file, plugin registration throws aRuntimeException. Missingext-dom,ext-libxml, orext-xmlreaderduring XML loading throws the same exception. The worker writes the error to standard error and exits without corrupting standard output framing. - Invalid
MAGO_SYMFONY_USER_CLASS. If the configured class does not exist in Mago's codebase or does not implementSymfony\Component\Security\Core\User\UserInterface, the worker writes a warning to standard error once. It leavesgetUser()unnarrowed and continues analysis.