#!php.exe -q if (!function_exists('hex2bin')) { // first include in php 5.4 function hex2bin($str) { $sbin = ""; $len = strlen($str); for ($i = 0; $i < $len; $i += 2) { $sbin .= pack("H*", substr($str, $i, 2)); } return $sbin; } } // // /** * 全局 * @staticvar CRedisUtil $gRedis * @return \CRedisUtil */ function gRedis() { static $gRedis; if ($gRedis == null) { $gRedis = new CRedisUtil(); $host = '192.168.10.51'; $port = '6666'; $pwd = 'wanggang1985'; $gRedis->conn($host, $port, $pwd); } return $gRedis; } function output($key, $value) { if (strpos($key, '-info') !== FALSE) { // userinfo $userinfo = JsonUtil::decode($value); if (property_exists($userinfo, 'user') // && property_exists($userinfo->user, 'ts') // && (day() - day($userinfo->user->ts) > 60)) { // 距上次登录60天以上了 // uid, zoneid, tsday, info(bin2hex(gzcompress()) $uid = $userinfo->user->oId; $zoneid = $userinfo->zoneid; $tsday = day($userinfo->user->ts); $info = bin2hex(gzdeflate($value)); $SQL = sprintf("call mgodpay.insertUserInfo('%s',%d,%d,'%s');", $uid, $zoneid, $tsday, $info); daoInst()->exec($SQL); echo $key . "\r\n"; return; } } $redis = gRedis(); $redis->set($key, $value); // $handle = fopen(__DIR__ . "/datas4/" . "$key.txt", "w"); // fwrite($handle, $value); // fclose($handle); } if ($argc <= 1 # 未传参数的情况下 || $argv[1] == "-h" || $argv[1] == "\\h") { # 或者是输入\h -h 查询帮助 echo " usage: php.exe $argv[0] dumpfilename \n"; echo " output: a txt file that use key as filename,value as contents.\n"; echo "\t(attension: to avoid too many output in console, filter is suggested.)\n"; } else { $n = 1; $filename = $argv[1]; $zoneid = intval(str_replace('cmem_zone', '', $filename)); if (!file_exists($filename)) { echo " file $filename not exist!"; } else { $handle = fopen($filename, "rb"); # 打开文件 if ($handle) { while (( $line = fgets($handle)) !== false) { $strarr = explode(" ", $line); $key = hex2bin($strarr[0]); $sec = $strarr[1]; $type = (int) substr($sec, 0, 8); $value = hex2bin(substr($sec, 8)); // echo "type: $type\n\ndecoded value: \n\n$value\n\n"; if ($type == 2) { $value = gzuncompress($value); // echo "\n\ndecoded value: \n\n$value\n\n"; } // echo "\"". $strarr[0]."\":".$value ."\n"; output("$key-zone$zoneid", $value); if ($n++ % 50 == 0) { echo "dealed $n records!\n"; // break; } } if (!feof($handle)) { // echo "Error: unexpected fgets() fail\n" ; } fclose($handle); } } }