我目前在我的数据库中生成大约34k引脚/ auths,当我运行它时,它只是说This webpage is not available
并说apache崩溃了。我不确定是什么导致它崩溃,因为它到目前为止产生了34k而没有问题。如果我能得到关于导致我的脚本崩溃的指针或任何内容,那就太棒了。谢谢。我也在本地wamp服务器上运行它。所以它给了我一个apache崩溃弹出窗口,但我似乎无法让它再次显示。
编辑这是崩溃弹出信息:
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_httpd.exe_7bb4b47e7db260ba266dfdf76b7ba24f8a5e099_cab_175bb644\WERB55A.tmp.appcompat.txt
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_httpd.exe_7bb4b47e7db260ba266dfdf76b7ba24f8a5e099_cab_175bb644\WERB56A.tmp.WERInternalMetadata.xml
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_httpd.exe_7bb4b47e7db260ba266dfdf76b7ba24f8a5e099_cab_175bb644\WERB5E9.tmp.mdmp
错误日志:
[Sat Apr 12 19:17:01.362346 2014] [core:notice] [pid 3124:tid 412] AH00094: Command line: 'c:\\wamp\\bin\\apache\\apache2.4.4\\bin\\httpd.exe -d C:/wamp/bin/apache/Apache2.4.4'
[Sat Apr 12 19:17:01.363346 2014] [mpm_winnt:notice] [pid 3124:tid 412] AH00418: Parent: Created child process 940
[Sat Apr 12 19:17:01.599360 2014] [mpm_winnt:notice] [pid 940:tid 308] AH00354: Child: Starting 150 worker threads.
[Sat Apr 12 19:17:04.302514 2014] [mpm_winnt:notice] [pid 3124:tid 412] AH00428: Parent: child process 940 exited with status 255 -- Restarting.
[Sat Apr 12 19:17:04.389519 2014] [mpm_winnt:notice] [pid 3124:tid 412] AH00455: Apache/2.4.4 (Win64) PHP/5.4.12 configured -- resuming normal operations
[Sat Apr 12 19:17:04.389519 2014] [mpm_winnt:notice] [pid 3124:tid 412] AH00456: Server built: Feb 22 2013 22:08:37
[Sat Apr 12 19:17:04.389519 2014] [core:notice] [pid 3124:tid 412] AH00094: Command line: 'c:\\wamp\\bin\\apache\\apache2.4.4\\bin\\httpd.exe -d C:/wamp/bin/apache/Apache2.4.4'
[Sat Apr 12 19:17:04.391519 2014] [mpm_winnt:notice] [pid 3124:tid 412] AH00418: Parent: Created child process 2996
[Sat Apr 12 19:17:04.647534 2014] [mpm_winnt:notice] [pid 2996:tid 308] AH00354: Child: Starting 150 worker threads.
代码:
<?php
ini_set('xdebug.max_nesting_level', 1000000); //this is to fix the recursion?
ini_set('max_execution_time', 3000000); //300 seconds = 5 minutes
ini_set('memory_limit', -1);
ini_set('error_reporting', E_ALL);
//Enter your database connection details here.
$host = 'localhost';
$db_name = 'pins';
$db_username = 'root';
$db_password = '';
date_default_timezone_set('America/Los_Angeles');
try
{
$pdo = new PDO('mysql:host='. $host .';dbname='.$db_name, $db_username, $db_password);
}
catch (PDOException $e)
{
exit('Error Connecting To DataBase');
}
$starttime = microtime(true);
class lists
{
public $pdo;
function __construct($pdo)
{
$this->pdo = $pdo;
}
function duplicateCode($code)
{
$query = $this->pdo->prepare("SELECT 1 FROM pins WHERE pins_pin = ?");
$query->bindValue(1, $code);
$query->execute();
return $query->fetch();
}
function generateCode()
{
$code = "AA" . substr(str_shuffle('0123456789'), 0, 8);
if($this->duplicateCode($code))
{
return $this->generateCode();
}
else
{
return $code;
}
}
function generatePin($code)
{
$query = $this->pdo->prepare("INSERT INTO pins (pins_pin) VALUES (?)");
$query->bindValue(1, $code);
$query->execute();
return;
}
}
function post_to_url($url, $data) {
$fields = '';
foreach ($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($post);
curl_close($post);
return $result;
}
$list = new lists($pdo);
for($i = 0; $i < 100000; $i++)
{
$code = $list->generateCode();
$pin = $list->generatePin($code);
}
$endtime = microtime(true);
$duration = $endtime - $starttime; //calculates total time taken
echo $duration;
?>
答案 0 :(得分:1)
重复调用lists::generateCode()
可能会超出内部递归限制。
一个简单的解决方法是消除递归:
function generateCode()
{
do {
$code = "AA" . substr(str_shuffle('0123456789'), 0, 8);
} while ($this->duplicateCode($code));
return $code;
}
然而,这里有一个更基本的问题。您的代码生成的代码以两个As开头,然后包含6个数字,所有代码必须不同。只有10! ÷ (10 - 6)! = 151,200个可能的代码符合这种模式 - 一旦你生成了所有这些代码,就不会再有了,甚至这个纠正的代码也会无休止地循环。 (另外,如果str_shuffle()
没有访问所有可能的排列 - 这是完全可能的 - 那么可能的输出集将会比这更小。)
除非您要求所有六位数字都不同,否则我强烈建议您改为使用任何六位数的序列,例如:
$code = sprintf("AA%06d", rand(0, 999999));