大量のバッチ(php/mysql)でプロモーションコードを作成しようとしています。大量のユニークなプロモーションコードを生成する最も良い方法は何ですか?
$CurrentCodesInMyDB = "asdfasdf,asdfsdfx"; // this is a giant comma delimited string of the current promo codes in the database.
$PromoCodes = "";
for($i=0;$i<=30000;$i++)
{
$NewCode = GetNewCode($PromoCodes, $CurrentCodesInMyDB);
$PromoCodes .= $NewCode . ","; //this string gets used to allow them to download a txt file
//insert $newcode into database here
}
function GetNewCode($CurrentList, $ExistingList)
{
$NewPromo = GetRandomString();
if(strpos($CurrentList, $NewPromo) === false && strpos($ExistingList, $NewPromo) === false)
{
return $NewPromo;
}
else
{
return GetNewCode($CurrentList, $ExistingList);
}
}
function GetRandomString()
{
return "xc34cv87"; //some random 8 character alphanumeric string
}
私は10Kでバッチを実行すると、OKのようです:
現在、私のコードは次のようになります。しかし、クライアントは一度に30kを生成できるようにしたいと考えています。ループを30kまで上げると、私は問題を抱えています。私が作ることができる明らかなパフォーマンス調整や、これを行うことができる別の方法がありますか?
あなたが抱えている「問題」はどのようなキー配列をチェックされますか? – thetaiko
なぜコードを配列ではなく巨大な文字列に格納していますか? – Jens
コードはインデックス付きのテーブルに格納されます。テキストファイルにコンマ区切りのリストを書くことができるように、リストをメモリに保持していました。 – Jason