flarumchina/php-auto-update

PHP的自动更新器

1.0.0 2017-07-01 03:10 UTC

This package is not auto-updated.

Last update: 2024-09-23 07:30:13 UTC


README

Build Status

使用这个库,您的用户可以自动更新他们的应用程序实例到最新版本。我创建它作为一个概念验证,不知道它是否被用于某个地方。因此,请谨慎使用这个库,因为它可能会在出错时使您的用户软件无法使用。

安装

  • 通过composer安装库 visualappeal/php-auto-update
  • 在您的应用程序中创建一个更新文件/方法,包含您的更新程序(参见example/client/update/index.php
  • 在您的服务器上创建一个update.jsonupdate.ini文件(客户端应从中获取更新,参见example/server/update.jsonexample/server/update.ini

注意:请务必注意,PHP需要写入权限才能更新Web服务器上的文件

示例

客户端

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()) {
	//Install new update
	echo 'New Version: ' . $update->getLatestVersion();
} else {
	// No new update
	echo 'Your application is up to date';
}

该库支持desarrolla2/cache组件,您应该使用它!否则,客户端将在每次请求时下载更新ini/json文件。

服务器

您的服务器至少需要一个文件,客户端将从中检查更新。这可以是一个json或ini文件。请参阅example/server/中的示例。ini部分的键或json键是版本。这个库使用语义版本控制来比较版本。有关详细信息,请参阅semver.org。ini/json的值是更新zip文件的绝对URL。由于该库支持增量更新,zip文件只需包含自上次版本以来的更改即可。zip文件不需要放置在同一服务器上,也可以上传到S3或另一个云存储。

文档

有关文档,请参阅src/AutoUpdate.php中的注释或example目录中的示例。