Created
October 12, 2014 17:43
-
-
Save anonymous/1867bb9b944511fe7960 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getNextToken() { | |
$select = null; | |
$redisKey = 'current_token_id'; | |
$tokenFilename = SYSTEM_DIR.'/tokens_checked.txt'; | |
$file = file($tokenFilename, FILE_SKIP_EMPTY_LINES|FILE_IGNORE_NEW_LINES); | |
if ($file) { | |
$fileCount = count($file); | |
if ($fileCount) { | |
$redis = new Redis(); | |
//$redis->connect('/tmp/redis.sock'); | |
$redis->connect('127.0.0.1', 6379); | |
$tokenId = $redis->get($redisKey); | |
if (!$tokenId OR !isset($file[$tokenId])) { | |
$tokenId = 0; | |
} | |
$select = $file[$tokenId]; | |
$tokenId++; | |
$redis->set($redisKey, $tokenId); | |
} | |
} | |
return $select; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment