php实现促销功能,php – 什么是生成大量独特促销代码的最佳方式?

我正在尝试大批量创建促销代码(使用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批量生产时,似乎没问题.但客户希望能够一次产生30k.当我将循环撞到30k时,我一直遇到问题.我可以做出任何明显的性能调整,或者我可以采用不同的方式吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值