Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Self-update a phar archive?

Tags:

php

io

updates

phar

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).

like image 423
Camilo Martin Avatar asked Oct 22 '13 09:10

Camilo Martin


2 Answers

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.

like image 88
adam187 Avatar answered Sep 19 '22 14:09

adam187


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

like image 30
Tomas Votruba Avatar answered Sep 16 '22 14:09

Tomas Votruba