shici_tmp 表中只有10万多条数据。
每次都是运行几百次(次数不一定)的时候就停止了。
把$the_yuan1这个值改成固定值就可以运行完。这是为什么?<?php include './conn.php'; ?><?php //
//
mysql_query("SET NAMES 'UTF8'");
mysql_query("SET CHARACTER SET UTF8");
mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");
function rand0($len){
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$string=time();
for(;$len>=1;$len--){
$position=rand()%strlen($chars);
$position2=rand()%strlen($string);
$string=substr_replace($string,substr($chars,$position,1),$position2,0);
}
return $string;
}for($ji=0;$ji<10000;$ji++){
echo $ji.'-------AAAAAAAAAAAAAAAAAAAAAA<br>';
$the_yuan1=rand0(8);
$result1=mysql_query("SELECT * FROM shici_tmp where tmp=1 and yuanwen = '".$the_yuan1."' ");
$row1=mysql_fetch_row($result1);
while($row1){
$c_id=$row1[0];
$c_biaoti=$row1[1];
$row1=mysql_fetch_row($result1);
}
echo $ji.'-------BBBBBBBBBBBBBBBBBBBBB<br>';
}
echo "OKOKOKOKOKOKOKO";
?>
每次都是运行几百次(次数不一定)的时候就停止了。
把$the_yuan1这个值改成固定值就可以运行完。这是为什么?<?php include './conn.php'; ?><?php //
//
mysql_query("SET NAMES 'UTF8'");
mysql_query("SET CHARACTER SET UTF8");
mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");
function rand0($len){
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
$string=time();
for(;$len>=1;$len--){
$position=rand()%strlen($chars);
$position2=rand()%strlen($string);
$string=substr_replace($string,substr($chars,$position,1),$position2,0);
}
return $string;
}for($ji=0;$ji<10000;$ji++){
echo $ji.'-------AAAAAAAAAAAAAAAAAAAAAA<br>';
$the_yuan1=rand0(8);
$result1=mysql_query("SELECT * FROM shici_tmp where tmp=1 and yuanwen = '".$the_yuan1."' ");
$row1=mysql_fetch_row($result1);
while($row1){
$c_id=$row1[0];
$c_biaoti=$row1[1];
$row1=mysql_fetch_row($result1);
}
echo $ji.'-------BBBBBBBBBBBBBBBBBBBBB<br>';
}
echo "OKOKOKOKOKOKOKO";
?>
error_reporting(E_ALL);
看看有什么错误。
rand0 只是产生随机串,而这个随机串是否能在数据库中检索到,并无碍大局(因为你并没有做什么)
况且数据库操作所花费的时间,并不计算在 php 有效工作时间内
毕竟10w条数据每次都搜完整个表,没有索引还要搜1w次,这db负载也不低啊。
首先应该不是执行超时问题。。 tmp自动也没有建索引。
我将httpd-mpm.conf的参数设置成:
<IfModule mpm_winnt_module>
ThreadsPerChild 1000
MaxRequestsPerChild 50000
</IfModule>可以运行2个小时左右,大概2万多条,还是停止了。