【发布时间】:2023-03-11 13:15:01
【问题描述】:
我必须执行一次 PHP 代码才能在我的数据库中进行一些更改以获得更好的表。代码太重,向数据库发送超过 190000 个查询(包括选择和插入)。
现在的问题是,当我在浏览器上执行它时,在数据库中形成结果并设置为 echo 以检查它是否以正确的方式运行,我可以发现它已部分执行。页面上没有出现错误/警告/通知。
我将最大执行时间和所有相关设置设置为 1 小时,但它只需要 30 分钟并立即停止 for 循环。
这是我的部分代码的示例:
for ($i=9;$i<=19909; $i++){
$j=0;
$select= "select synonym from synonym where x_=". $i ."";
//echo $select;
//echo "</br>";
$select_result= mysqli_query($connection,$select);
if (mysqli_num_rows($select_result)>0) {
$row = mysqli_fetch_assoc($select_result);
$arra = explode("،",$row["synonym"]);
}
while ($arra[$j]){
$text=trim($arra[$j]);
$search="select word from semiresult where word='". $text ."'";
$search_result= mysqli_query($connection,$search);
if (mysqli_num_rows($search_result)==0) {
$insert="insert into semiresult (x, word, synonym) values ('','". $text."','".$syn."')";
}elseif (mysqli_num_rows($search_result)>0){
$repeat="UPDATE semiresult SET synonym=CONCAT(synonym,'".$syn2."') where word like'".$arra[$j]."'";
$repeat_result=mysqli_query($connection,$repeat) or die ('request "Could not execute SQL query" '.$repeat);
}
【问题讨论】:
-
你有什么问题?
-
你的问题是什么,你能显示这个“代码”吗?
-
我认为您的代码可能过于复杂。给我们一个你的代码例子......说20行左右。那么我们将能够更好地为您提供帮助。
-
问题是如何执行它
-
请输入代码...没有代码我们无法为您提供任何帮助。
标签: php mysql long-running-processes