Last active
August 29, 2015 14:04
-
-
Save kawa-/ce05b718f5edae3eb93a to your computer and use it in GitHub Desktop.
先のibt11.plの前に使うスクリプトで、指定された分だけユニークなキーのペアを作る。
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 | |
# generate unique pairs | |
# usage: $ php gen_upt11.php 10 > upt11.txt | |
define('NUM_PAIRS', $argv[1]); | |
define('MAX_USERS', 5000 * 10000); | |
$dbname = 'db01'; | |
$host = 'localhost'; | |
$user = 'root'; | |
$password = 'root'; | |
$table = 't11'; | |
$pairs = array(); | |
$pdo = new PDO( | |
'mysql:dbname=' . $dbname . ';host=' . $host . ';charset=latin1', $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => true) | |
); | |
while (TRUE) { | |
if (count($pairs) >= NUM_PAIRS) { | |
break; | |
} | |
$userid = rand(1, MAX_USERS); | |
$followerid = rand(1, MAX_USERS); | |
if (select($pdo, $table, $userid, $followerid) === FALSE) { | |
$pairs[] = array($userid, $followerid); | |
} | |
} | |
foreach ($pairs as $pair) { | |
echo $pair[0] . "\t" . $pair[1] . "\t" . (time()+rand(-100000000, 100000000)) . "\n"; | |
} | |
/* $iと$fの組み合わせが存在してればTRUE, 存在しなければFALSE */ | |
function select($pdo, $tablename, $i, $f) { | |
try { | |
$stmt = $pdo->prepare("select e from " . $tablename . " where e like :query"); | |
$stmt->bindValue(':query', $i . "-%", PDO::PARAM_STR); | |
$stmt->execute(); | |
$row = $stmt->fetch(PDO::FETCH_ASSOC); | |
if ($row === FALSE) { | |
return FALSE; | |
} | |
return TRUE; | |
} catch (PDOException $e) { | |
die("ERROR. " . $e->getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment