consolidation/self-update
Consolidation Self-Update adds safe, automated self-update support for PHP CLI apps. Check for new releases, download and replace the running PHAR, verify integrity, and manage backups/rollback—ideal for tooling built with Robo and Consolidation components.
Start by installing the package via Composer:
composer require consolidation/self-update
Next, create an updater class that extends Consolidation\SelfUpdate\UpdaterInterface or use the built-in Consolidation\SelfUpdate\Updater. Configure it with your PHAR’s current version and remote release endpoint (e.g., a GitHub releases API or JSON manifest). Implement a simple CLI command to trigger updates:
use Consolidation\SelfUpdate\Updater;
$updater = new Updater($currentVersion, $pharPath, $remoteUrl);
$updater->check(); // Returns true if update available
if ($updater->update()) {
// Success — restart or notify
}
For first-time use, add an update or self-update command to your main application and test with a local or staged manifest.
Application::registerCommands(): Add SelfUpdateCommand as a built-in command, making updates discoverable.GitHubStrategy, ZipStrategy, or implement custom ones (e.g., S3, internal repo) via Updater::setStrategy().update() only after check() + user confirmation. Use RollbackAwareInterface for atomic PHAR swaps (copy to temp, rename, signal success).--stable, --beta) to select release channels by overriding the strategy’s getReleaseUrl().install or post-update-cmd scripts to pre-download updates in deployment pipelines.phar.readonly = Off in php.ini for in-place PHAR replacement; otherwise use --force or fallback to copy()-based update.sys_get_temp_dir() for fallback.Authorization: token xxx for private repos); override createHttpClient() or pass a custom Guzzle client.StrategyInterface to add phar.signatures or GPG verification for security-critical deployments.version_compare() internally—avoid string comparisons for semantic versioning edge cases (e.g., 1.10 vs 1.9).Updater::rollback() if your strategy preserves previous artifacts (e.g., GitHub releases retain old PHARs).ProgressInterface to show download %; provide verbose (-vvv) output for low-level logging.How can I help you explore Laravel packages today?