0

我正在尝试使用以下代码生成 1500 身份验证代码:

<?php
include "../include/top.php";
$count=1500;
$end=0;
while ($end<$count)
{
//generate an authentication code
$string="ABCDEFGHJKLMNPQRSTUVWXYZ123456789";
$string= substr(str_shuffle($string),5,8) ;

//check whether generated code already exist
$query = "select count(*) from auth where code = '$string' ";
$stmt = prepare ($query);
execute($stmt);
$bind = mysqli_stmt_bind_result($stmt, $count);
check_bind_result($bind);
mysqli_stmt_fetch($stmt);
mysqli_stmt_free_result($stmt);

//If generated code does not already exist, insert it to Database table
if ($count == 0)
    {
    echo $string."<br>";
    $query = "insert into auth (Code) values ('$string')";
    $stmt = prepare ($query);
    execute($stmt);
    $end++;
    }
}
?>

它仅生成 1024 个代码,在浏览器中打印并插入数据库。然后生成错误:Fatal error: Maximum execution time of 60 seconds exceeded in...... 然后我在 php.ini 中将 max_execution_time 的值更改为 350 并重新启动 WAMP 并再次运行相同的脚本,但它生成只有不到 1000 个代码,浏览器显示加载直到完成 350 秒并产生错误:致命错误:超过 350 秒的最大执行时间......

实际上我想用这种方法生成十万个代码。如何为值成功运行此脚本

$count=100000
4

1 回答 1

0

有很多更有效的方法可以做到这一点。但是,如果您使用

 set_time_limit(0);
 ini_set("memory_limit", "-1");

你应该没有问题。

于 2014-03-31T14:36:57.267 回答