繁体   English   中英

PHP | 我如何让我的 php 脚本更新程序检查远程文本文件中是否有遗漏的版本?

[英]PHP | How would I make my php script updater check for missed versions from a remote text file?

我正在为我的 CMS 项目开发 PHP 更新程序。 它的作用是检查远程version.txt文件以查看它是否需要更新。 我的问题是,什么是用户仍然使用版本1.0 ,远程version.txt文件中定义的最新版本是1.3 我如何让我的更新程序依次更新到1.2版和1.3版? 我在下面提供了我的代码。

<?php

$phoenix_version = 1.0;
         $rc = @fsockopen("www.phoenix.ltda", 80, $errno, $errstr, 1);
        if (is_resource($rc))  {
        /* Update Version */
        $remote_version=trim(file_get_contents('https://phoenix.ltda/updates/version.txt'));
        $remote_version = preg_replace('/[^\\d.]+/', '', $remote_version);
        /* Current up to date version */
        $remote_current_version=trim(file_get_contents('https://phoenix.ltda/updates/current-version.txt'));
        $remote_current_version = preg_replace('/[^\\d.]+/', '', $remote_current_version);
        if(version_compare($remote_version, $phoenix_version) ==  1){
            $new_version = true;
        }else{
            $new_version = false; 
        }
        
        }else{
        echo "The Phoenix PHP updater could not be reached by this server. Please try again later or contact the Phoenix PHP team.";
        }
        
        
        if(!empty($_POST)) {
            $_POST['update'] = Database::clean_string($_POST['update']);
            $values['update'] = $_POST['update'];
            
            $clean_remote_version = preg_replace('/[.,]/', '', $remote_version);
            
            $ch = curl_init();
            $source = 'https://phoenix.ltda/updates/phoenix-update'.$clean_remote_version.'.zip';
            curl_setopt($ch, CURLOPT_URL, $source);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $data = curl_exec ($ch);
            curl_close ($ch);

            $destination = ROOT_PATH . '/phoenix-update'.$clean_remote_version.'.zip';
            $file = fopen($destination, "w+");
            fputs($file, $data);
            fclose($file);

        }
?>

如何让它更新到最新版本? 像 1.0 到 1.1 到 1.2 一直到最新版本? 解决这个问题的最佳方法是什么?

如果更新只是代码更新,则这不是问题。 但是当数据库有多个更新时,您需要编写数据库迁移并逐个版本地运行它们(查看 Laravel 或 Sphinx 以获得很好的示例)。 此外,您的更新脚本非常复杂; 最好将当前版本发布到 API 上,并让它以最终更新的版本进行响应 - 这也可用于发送更新批处理 URL,而不是获取单个文件。 好吧,如果 API 只响应下一个版本(而不是最新版本),这甚至可以工作 - 但批量运行可能会更优雅。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM