PHP code example of bennetgallein / php-auto-update

1. Go to this page and download the library: Download bennetgallein/php-auto-update library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bennetgallein / php-auto-update example snippets




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';
}