stickee/sync 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stickee/sync

Composer 安装命令:

composer require stickee/sync

包简介

Stickee sync module - synchronise database tables

关键字:

README 文档

README

This a composer module for synchronising files or database tables between two servers.

NOTE: Foreign key checks are disabled during import

Installation

composer require stickee/sync

This module ships with a Laravel service provider which will be automatically registered.

Manual registration

The module can be manually registered by adding this to the providers array in config/app.php:

\Stickee\Sync\ServiceProvider::class,

Usage for Servers (Sending Data)

Add the routes to your routes/api.php by calling \Stickee\Sync\ServiceProvider::routes();. You will usually want to prefix the URL and add some form of authentication, for example:

Route::middleware('auth:api')
    ->prefix('sync')
    ->name('sync.')
    ->group(function () {
        \Stickee\Sync\ServiceProvider::routes();
    });

Configuration

Run php artisan vendor:publish --provider="Stickee\Sync\ServiceProvider" to publish the configuration files, then fill in tables and directories in sync-server.php.

Usage for Clients (Receiving Data)

Configuration

Run php artisan vendor:publish --provider="Stickee\Sync\ServiceProvider" to publish the configuration files, then fill in tables and directories in sync-client.php. Set the following in your .env file:

  • SYNC_API_URL: The server URL, e.g. https://example.com/api/sync

If you have added authentication, then you will need to make the Guzzle client authenticate. For api-token authenticaion, add this to you config/sync-client.php

'api_key' => env('SYNC_API_KEY'),

and add SYNC_API_KEY=XXXXXXX to your .env file.

Then in AppServiceProvider::register() add:

app()->when(\Stickee\Sync\Client::class)
    ->needs(\GuzzleHttp\Client::class)
    ->give(function () {
        $config = [
            'headers' => [
                'Authorization' => 'Bearer ' . \Stickee\Sync\Helpers::clientConfig('api_key'),
                'Accept' => 'application/json',
            ],
        ];

        return new \GuzzleHttp\Client($config);
    });

Commands

The package supplies php artisan sync:sync to run a synchronisation from the command line.

Developing

The easiest way to make changes is to make the project you're importing the module in to load the module from your filesystem instead of the composer repository, like this:

  1. composer remove stickee/sync
  2. Edit composer.json and add
    "repositories": [
        {
            "type": "path",
            "url": "../sync"
        }
    ]
    
    where "../sync" is the path to where you have this project checked out
  3. composer require stickee/sync@dev

NOTE: Do not check in your composer.json like this!

Database tables

Method 1:

  • Client hashes its local copy of the table
  • Client sends a getTableHash request to the server
  • If the hashes are the same, there is nothing to do so stop
  • Client sends a getTable request
  • Client imports the response, which is merged in to the existing table

Method 2:

  • Client hashes its local copy of the table
  • Client sends a getTable request to the server, including the hash
  • If the hashes are the same, the server will respond 304 Not Modified
  • Client imports the response, which is merged in to the existing table

Tables can be hashed using a class that implements \Stickee\Sync\Interfaces\TableHasherInterface

Files

  • Client hashes its local copy of the files
  • Client sends a getFileHashes request to the server
  • Client compares the hashes and builds a list of files it needs to delete / download
  • Client deletes extraneous files
  • Client splits the list of files to fetch into chunks
  • For each chunk, the client sends a getFiles request
  • Files are saved to the disk

Testing

First copy phpunit.xml.dist to phpunit.xml and fill in your MySQL database details. Run unit tests with the following command:

./vendor/bin/phpunit -v

stickee/sync 适用场景与选型建议

stickee/sync 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.61k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 08 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「sync」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 stickee/sync 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 stickee/sync 我们能提供哪些服务?
定制开发 / 二次开发

基于 stickee/sync 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2020-08-05