Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Swoole\Component; use Swoole; /** * Class Redis * @package Swoole\Compo..

Decoded Output download

<?php
namespace Swoole\Component;
use Swoole;

/**
 * Class Redis
 * @package Swoole\Component
 */
class Redis
{
    const READ_LINE_NUMBER = 0;
    const READ_LENGTH = 1;
    const READ_DATA = 2;

    /**
     * @var \Redis
     */
    protected $_redis;

    public $config;

    public static $prefix = "autoinc_key:";

    /**
     * ID
     * @param $appKey
     * @param int $init_id
     * @return bool|int
     */
    function getIncreaseId($appKey, $init_id = 1)
    {
        if (empty($appKey))
        {
            return false;
        }
        $main_key = self::$prefix . $appKey;
        // 1
        if ($this->_redis->exists($main_key))
        {
            $inc = $this->_redis->incr($main_key);
            if (empty($inc))
            {
                \Swoole::$php->log->put("redis::incr() failed. Error: ".$this->_redis->getLastError());
                return false;
            }
            return $inc;
        }
        //iffalse,key
        else if($this->_redis->getLastError())
        {
            return false;
        }
        //key
        else
        {
            $init = $this->_redis->set($main_key, $init_id);
            if ($init == false)
            {
                \Swoole::$php->log->put("redis::set() failed. Error: ".$this->_redis->getLastError());
                return false;
            }
            else
            {
                return $init_id;
            }
        }
    }

    function __construct($config)
    {
        $this->config = $config;
        $this->connect();
    }

    function connect()
    {
        try
        {
            if ($this->_redis)
            {
                unset($this->_redis);
            }
            $this->_redis = new \Redis();
            if ($this->config['pconnect'])
            {
                $this->_redis->pconnect($this->config['host'], $this->config['port'], $this->config['timeout']);
            }
            else
            {
                $this->_redis->connect($this->config['host'], $this->config['port'], $this->config['timeout']);
            }
            
            if (!empty($this->config['password']))
            {
                $this->_redis->auth($this->config['password']);
            }
            if (!empty($this->config['database']))
            {
                $this->_redis->select($this->config['database']);
            }
        }
        catch (\RedisException $e)
        {
            \Swoole::$php->log->error(__CLASS__ . " Swoole Redis Exception" . var_export($e, 1));
            return false;
        }
    }

    function __call($method, $args = array())
    {
        $reConnect = false;
        while (1)
        {
            try
            {
                $result = call_user_func_array(array($this->_redis, $method), $args);
            }
            catch (\RedisException $e)
            {
                //
                if ($reConnect)
                {
                    throw $e;
                }

                \Swoole::$php->log->error(__CLASS__ . " [" . posix_getpid() . "] Swoole Redis[{$this->config['host']}:{$this->config['port']}]
                 Exception(Msg=" . $e->getMessage() . ", Code=" . $e->getCode() . "), Redis->{$method}, Params=" . var_export($args, 1));
                if ($this->_redis->isConnected())
                {
                    $this->_redis->close();
                }
                $this->connect();
                $reConnect = true;
                continue;
            }
            return $result;
        }
        //
        return false;
    }

    static function write($fp, $content)
    {
        $length = strlen($content);
        for ($written = 0; $written < $length; $written += $n)
        {
            if ($length - $written >= 8192)
            {
                $n = fwrite($fp, substr($content, 8192));
            }
            else
            {
                $n = fwrite($fp, substr($content, $written));
            }
            //
            if (empty($n))
            {
                break;
            }
        }
        return $written;
    }

    /**
     * @param $file
     * @param $dstRedisServer
     * @param int $seek
     * @return bool
     */
    static function syncFromAof($file, $dstRedisServer, $seek = 0)
    {
        $fp = fopen($file, 'r');
        if (!$fp)
        {
            return false;
        }
        //
        if ($seek > 0)
        {
            fseek($fp, $seek);
        }

        //Redis
        $dstRedis = stream_socket_client($dstRedisServer, $errno, $errstr, 10);
        if (!$dstRedis)
        {
            return false;
        }

        $n_bytes = $seek;
        $n_lines = 0;
        $n_success = 0;
        $_send = '';
        $patten = "#^\*(\d+)
$#";

        readfile:
        while(!feof($fp))
        {
            $line = fgets($fp, 8192);
            if ($line === false)
            {
                echo "line empty
";
                break;
            }
            $n_lines++;
            $r = preg_match($patten, $line);
            if ($r)
            {
                if ($_send)
                {
                    if (self::write($dstRedis, $_send) === false)
                    {
                        die("Redis. $_send");
                    }
                    $n_bytes += strlen($_send);
                    //
                    if (fread($dstRedis, 8192) == false)
                    {
                        echo "Redis. $_send
";
                        for($i = 0; $i < 10; $i++)
                        {
                            $dstRedis = stream_socket_client($dstRedisServer, $errno, $errstr, 10);
                            if (!$dstRedis)
                            {
                                echo "Redis($dstRedisServer), 1.
";
                                sleep(1);
                            }
                        }
                        if (!$dstRedis)
                        {
                            echo "Redis($dstRedisServer)
";
                            return false;
                        }
                        $_send = $line;
                        continue;
                    }

                    $n_success ++;
                    if ($n_success % 10000 == 0)
                    {
                        $seek = ftell($fp);
                        echo "KEY: $n_success, LINE: $n_lines, BYTE: {$n_bytes}, SEEK: {$seek}. 
";
                    }
                }
                $_send = $line;
            }
            else
            {
                $_send .= $line;
            }
        }

        wait:
        //100ms
        sleep(2);
        $seek = ftell($fp);
        echo "read eof, seek={$seek}
";
        //
        fclose($fp);
        $fp = fopen($file, 'r');
        if (!$fp)
        {
            exit("seek=$seek
");
        }
        if (fseek($fp, $seek) < 0)
        {
            exit("feek($seek)
");
        }
        goto readfile;
    }
}
 ?>

Did this file decode correctly?

Original Code

<?php
namespace Swoole\Component;
use Swoole;

/**
 * Class Redis
 * @package Swoole\Component
 */
class Redis
{
    const READ_LINE_NUMBER = 0;
    const READ_LENGTH = 1;
    const READ_DATA = 2;

    /**
     * @var \Redis
     */
    protected $_redis;

    public $config;

    public static $prefix = "autoinc_key:";

    /**
     * ID
     * @param $appKey
     * @param int $init_id
     * @return bool|int
     */
    function getIncreaseId($appKey, $init_id = 1)
    {
        if (empty($appKey))
        {
            return false;
        }
        $main_key = self::$prefix . $appKey;
        // 1
        if ($this->_redis->exists($main_key))
        {
            $inc = $this->_redis->incr($main_key);
            if (empty($inc))
            {
                \Swoole::$php->log->put("redis::incr() failed. Error: ".$this->_redis->getLastError());
                return false;
            }
            return $inc;
        }
        //iffalse,key
        else if($this->_redis->getLastError())
        {
            return false;
        }
        //key
        else
        {
            $init = $this->_redis->set($main_key, $init_id);
            if ($init == false)
            {
                \Swoole::$php->log->put("redis::set() failed. Error: ".$this->_redis->getLastError());
                return false;
            }
            else
            {
                return $init_id;
            }
        }
    }

    function __construct($config)
    {
        $this->config = $config;
        $this->connect();
    }

    function connect()
    {
        try
        {
            if ($this->_redis)
            {
                unset($this->_redis);
            }
            $this->_redis = new \Redis();
            if ($this->config['pconnect'])
            {
                $this->_redis->pconnect($this->config['host'], $this->config['port'], $this->config['timeout']);
            }
            else
            {
                $this->_redis->connect($this->config['host'], $this->config['port'], $this->config['timeout']);
            }
            
            if (!empty($this->config['password']))
            {
                $this->_redis->auth($this->config['password']);
            }
            if (!empty($this->config['database']))
            {
                $this->_redis->select($this->config['database']);
            }
        }
        catch (\RedisException $e)
        {
            \Swoole::$php->log->error(__CLASS__ . " Swoole Redis Exception" . var_export($e, 1));
            return false;
        }
    }

    function __call($method, $args = array())
    {
        $reConnect = false;
        while (1)
        {
            try
            {
                $result = call_user_func_array(array($this->_redis, $method), $args);
            }
            catch (\RedisException $e)
            {
                //
                if ($reConnect)
                {
                    throw $e;
                }

                \Swoole::$php->log->error(__CLASS__ . " [" . posix_getpid() . "] Swoole Redis[{$this->config['host']}:{$this->config['port']}]
                 Exception(Msg=" . $e->getMessage() . ", Code=" . $e->getCode() . "), Redis->{$method}, Params=" . var_export($args, 1));
                if ($this->_redis->isConnected())
                {
                    $this->_redis->close();
                }
                $this->connect();
                $reConnect = true;
                continue;
            }
            return $result;
        }
        //
        return false;
    }

    static function write($fp, $content)
    {
        $length = strlen($content);
        for ($written = 0; $written < $length; $written += $n)
        {
            if ($length - $written >= 8192)
            {
                $n = fwrite($fp, substr($content, 8192));
            }
            else
            {
                $n = fwrite($fp, substr($content, $written));
            }
            //
            if (empty($n))
            {
                break;
            }
        }
        return $written;
    }

    /**
     * @param $file
     * @param $dstRedisServer
     * @param int $seek
     * @return bool
     */
    static function syncFromAof($file, $dstRedisServer, $seek = 0)
    {
        $fp = fopen($file, 'r');
        if (!$fp)
        {
            return false;
        }
        //
        if ($seek > 0)
        {
            fseek($fp, $seek);
        }

        //Redis
        $dstRedis = stream_socket_client($dstRedisServer, $errno, $errstr, 10);
        if (!$dstRedis)
        {
            return false;
        }

        $n_bytes = $seek;
        $n_lines = 0;
        $n_success = 0;
        $_send = '';
        $patten = "#^\\*(\d+)\r\n$#";

        readfile:
        while(!feof($fp))
        {
            $line = fgets($fp, 8192);
            if ($line === false)
            {
                echo "line empty\n";
                break;
            }
            $n_lines++;
            $r = preg_match($patten, $line);
            if ($r)
            {
                if ($_send)
                {
                    if (self::write($dstRedis, $_send) === false)
                    {
                        die("Redis. $_send");
                    }
                    $n_bytes += strlen($_send);
                    //
                    if (fread($dstRedis, 8192) == false)
                    {
                        echo "Redis. $_send\n";
                        for($i = 0; $i < 10; $i++)
                        {
                            $dstRedis = stream_socket_client($dstRedisServer, $errno, $errstr, 10);
                            if (!$dstRedis)
                            {
                                echo "Redis($dstRedisServer), 1.\n";
                                sleep(1);
                            }
                        }
                        if (!$dstRedis)
                        {
                            echo "Redis($dstRedisServer)\n";
                            return false;
                        }
                        $_send = $line;
                        continue;
                    }

                    $n_success ++;
                    if ($n_success % 10000 == 0)
                    {
                        $seek = ftell($fp);
                        echo "KEY: $n_success, LINE: $n_lines, BYTE: {$n_bytes}, SEEK: {$seek}. \n";
                    }
                }
                $_send = $line;
            }
            else
            {
                $_send .= $line;
            }
        }

        wait:
        //100ms
        sleep(2);
        $seek = ftell($fp);
        echo "read eof, seek={$seek}\n";
        //
        fclose($fp);
        $fp = fopen($file, 'r');
        if (!$fp)
        {
            exit("seek=$seek\n");
        }
        if (fseek($fp, $seek) < 0)
        {
            exit("feek($seek)\n");
        }
        goto readfile;
    }
}

Function Calls

None

Variables

None

Stats

MD5 137ad51f241614ee269d6e18dbd4dde0
Eval Count 0
Decode Time 199 ms