parkerj/php-auto-update

PHP 自动更新器

1.0.0 2017-11-22 17:49 UTC

This package is auto-updated.

Last update: 2024-09-04 07:47:13 UTC


README

Build Status

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

安装

  • 通过 composer 安装库 parkerj/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 \ParkerJ\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 部分 key 分别 json key 是版本。此库使用语义版本控制来比较版本。有关详细信息,请参阅 semver.org。ini/json 值是更新 zip 文件的绝对 URL。由于该库支持增量更新,zip 文件只需包含自上次版本以来的更改。zip 文件不需要放置在同一个服务器上,也可以上传到 S3 或其他云存储。

文档

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