bennetgallein / php-auto-update
PHP 自动更新器
0.17.0
2023-02-18 09:42 UTC
Requires
- php: >= 7.1.0
- ext-curl: *
- ext-json: *
- ext-zip: *
- composer/semver: ^3.0
- desarrolla2/cache: 2.1.*
- monolog/monolog: ^2.0
- tracy/tracy: ^2.5
Requires (Dev)
- phpunit/phpunit: ^8.0
README
使用这个库,您的用户可以自动更新他们应用程序的实例到最新版本。我创建它作为一个概念验证,不知道它是否被某处使用。所以请谨慎使用这个库,因为它可能会在出错时使您的用户软件无法使用。
注意
- 似乎不支持.ini文件。
安装
- 通过composer安装库 bennetgallein/php-auto-update
- 在您的应用程序中创建一个更新文件/方法,包含您的更新程序(参见
example/client/update/index.php
) - 在您的服务器上创建一个
update.json
或update.ini
(客户端应从中获取更新,参见example/server/update.json
或example/server/update.ini
)
重要:请注意,PHP需要写入权限来更新网站服务器上的文件
示例
客户端
update.php/some method
此文件将安装更新。示例请参见example/client/update/index.php
检查新版本
您始终可以检查新版本,例如在页脚中。它可以看起来像这样
<?php require(__DIR__ . '/../../../vendor/autoload.php'); use \VisualAppeal\AutoUpdate; // Download the zip update files to `__DIR__ . '/temp'` // Copy the contents of the zip file to the current directory `__DIR__` // The update process should last 60 seconds max $update = new AutoUpdate(__DIR__ . '/temp', __DIR__, 60); $update->setCurrentVersion('0.1.0'); // Current version of your application. This value should be from a database or another file which will be updated with the installation of a new version $update->setUpdateUrl('http://php-auto-update.app/update/'); //Replace the url with your server update url // The following two lines are optional $update->addLogHandler(new Monolog\Handler\StreamHandler(__DIR__ . '/update.log')); $update->setCache(new Desarrolla2\Cache\Adapter\File(__DIR__ . '/cache'), 3600); //Check for a new update if ($update->checkUpdate() === false) die('Could not check for updates! See log file for details.'); // Check if new update is available if ($update->newVersionAvailable()) { echo 'New Version: ' . $update->getLatestVersion(); // Simulate or install? $simulate = true; //Install new update $result = $update->update($simulate); if ($result === true) { echo 'Update simulation successful<br>'; } else { echo 'Update simulation failed: ' . $result . '!<br>'; } } else { // No new update echo 'Your application is up to date'; }
此库支持desarrolla2/cache
组件,您应该使用它!否则,客户端将每次请求都下载更新ini/json文件。
服务器
您的服务器至少需要一个文件,客户端将从该文件检查更新。有关示例,请参见example/server/
。此库使用语义版本控制来比较版本。有关详细信息,请参见semver.org。ini/json值是更新zip文件的绝对URL。由于此库支持增量更新,zip文件只需要包含自上次版本以来的更改。zip文件不需要放置在同一服务器上,也可以上传到S3或其他云存储。
文档
有关文档,请参阅src/AutoUpdate.php
中的注释或example
目录中的示例。