I'm planning on creating a bunch of PHP scripts in a phar archive (for easy deployment) and allowing it to self-update from a known repository.
How should a phar archive, on a live website, update itself? Not update its contents, but just replacing itself (from a new.phar
previously downloaded to /tmp
or something) would be enough.
I'm specifically concerned about pitfalls on "replacing myself" in PHP, also considering requests could be underway (the script will primarily be called from the web, by AJAX).
You can check how composer does self update:
https://github.com/composer/composer/blob/master/src/Composer/Command/SelfUpdateCommand.php
But like @OddEssay said it would probably be better to use composer as package manager.
Check Distributing CLI PHP App with Ease article.
There is also mentioned PHP-Phar-Update package, that handle PHAR self-updating.
For implementation example, you can check Self-update command of PhpDocumentor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With