PHP code example of tourze / workerman-anti-replay-protocol

1. Go to this page and download the library: Download tourze/workerman-anti-replay-protocol 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/ */

    

tourze / workerman-anti-replay-protocol example snippets


use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Psr\Log\LoggerInterface;
use Tourze\Workerman\AntiReplayProtocol\AntiReplay;
use Tourze\Workerman\AntiReplayProtocol\Config;

// 创建配置
$config = new Config();
$config->setCache(new FilesystemAdapter());
$config->setLogger($logger); // 实现了LoggerInterface的日志对象
$config->setCheckLength(32); // 可选,默认为32
$config->setTtl(60 * 60 * 24); // 可选,默认为24小时

// 设置防重放协议配置
AntiReplay::setConfig($config);

// 在Workerman中使用
$worker = new Worker('AntiReplay://0.0.0.0:8080');
$worker->onMessage = function($connection, $data) {
    // 处理数据
};