- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前遇到内存使用问题 - 但我不知道是哪里。我已经尝试用 for 循环替换我的一些 foreach 循环或通过向数据库发出另一个查询,但我仍然遇到同样的错误 - “ fatal error :允许的 134217728 字节的内存大小耗尽(试图分配 72 字节)在在第 109 行”。任何人都可以就可能导致问题的原因提供一些见解吗?谢谢!
@Patrick 回答后的代码:
$participating_swimmers = array();
$event_standings = array();
$qualifying_times = array();
$events = array();
$current_event = '';
$select_times_sql = "SELECT event, time, name, year, team, time_standard, date_swum
FROM demo_times_table
WHERE sex = 'M' AND (time_standard = 'A' OR time_standard = 'B')
ORDER BY event, time ASC";
$select_times_query = mysql_query($select_times_sql);
//Create array with the current line's swimmer's info
while ($swimmer_info = mysql_fetch_assoc($select_times_query)) {
if($current_event != $swimmer_info['event']){
$events[] = $current_event = $swimmer_info['event'];
}
//Create array with the current line's swimmer's info
$swimmer_info["time"] = $select_times_row['time'];
$swimmer_info["name"] = $select_times_row['name'];
$swimmer_info["year"] = $select_times_row['year'];
$swimmer_info["team"] = $select_times_row['team'];
$swimmer_info["time_standard"] = $select_times_row['time_standard'];
$swimmer_info["date_swum"] = $select_times_row['date_swum'];
//Create "Top 8" list - if more than 8 A cuts, take them all
if (($swimmer_info["time_standard"] == "A") || ($swimmer_info["time_standard"] == "B")) {
//Check if there are 8 or less entries in the current event, or if the swim is an A cut
if ((count($event_standings[$current_event]) < 8) || ($swimmer_info["time_standard"] == "A")) {
//Add swimmer to the list of invites
$event_standings[$current_event][] = $swimmer_info;
//Keep only the identifying information about the swimmer
$condensed_swimmer_info["name"] = $swimmer_info["name"];
$condensed_swimmer_info["year"] = $swimmer_info["year"];
$condensed_swimmer_info["team"] = $swimmer_info["team"];
//Check if swimmers name already appears in list
if (!in_array($condensed_swimmer_info, $participating_swimmers)) {
//It is a unique user - add them to the list
$participating_swimmers[] = $condensed_swimmer_info;
}
} else {
//Add the qualifying time that did not fit into the list to a list of qualifying times
$qualifying_times[$current_event][] = $swimmer_info;
}
}
}
//Sort each array of times in descending order
arsort($event_standings);
arsort($qualifying_times);
$num_of_swimmers = count($participating_swimmers);
while ($num_of_swimmers < 80) {
foreach ($events as $loe) {
$num_of_qualifying_times = count($qualifying_times[$loe]);
$swimmer_info = $qualifying_times[$loe][$num_of_qualifying_times-1];
$event_standings[$loe][] = $swimmer_info;
//Keep only the identifying information about the swimmer
$condensed_swimmer_info["name"] = $swimmer_info["name"];
$condensed_swimmer_info["year"] = $swimmer_info["year"];
$condensed_swimmer_info["team"] = $swimmer_info["team"];
//Check if swimmers name already appears in list
if (!in_array($condensed_swimmer_info, $participating_swimmers)) {
//It is a unique user - add them to the list
$participating_swimmers[] = $condensed_swimmer_info;
}
//Remove time from array of qualifying times
unset($qualifying_times[$loe][$num_of_qualifying_times-1]);
}
$new_num_of_swimmers = count($participating_swimmers);
if($num_of_swimmers == $new_num_of_swimmers) break;
else $num_of_swimmers = $new_num_of_swimmers;
}
arsort($event_standings);
arsort($qualifying_times);
foreach($event_standings as $loe => $event_swimmer) {
echo "<h1>",$loe,"</h1><br />";
foreach ($event_swimmer as $es) {
echo $es["time"]," ",$es["name"]," ",$es["team"],"<br />";
}
}
最佳答案
数据库中的大数据是 95% 的问题!- 尝试在查询中使用 limit x,y
,并将这些查询放入某个循环中。- 参见 http://php.net/manual/en/function.mysql-free-result.php可能有帮助
<?php
$participating_swimmers = array();
$event_standings = array();
$qualifying_times = array();
$select_times_sql = "SELECT *
FROM demo_times_table
WHERE sex = 'M'
ORDER BY time ASC";
$select_times_query = mysql_query($select_times_sql);
while ($select_times_row = mysql_fetch_assoc($select_times_query)) {
//Create array with the current line's swimmer's info
$swimmer_info["time"] = $select_times_row['time'];
$swimmer_info["name"] = $select_times_row['name'];
$swimmer_info["year"] = $select_times_row['year'];
$swimmer_info["team"] = $select_times_row['team'];
$swimmer_info["time_standard"] = $select_times_row['time_standard'];
$swimmer_info["date_swum"] = $select_times_row['date_swum'];
//Create "Top 8" list - if more than 8 A cuts, take them all
if (($swimmer_info["time_standard"] == "A") || ($swimmer_info["time_standard"] == "B")) {
//Check if there are 8 or less entries in the current event, or if the swim is an A cut
if ((count($event_standings[$current_event]) < 8) || ($swimmer_info["time_standard"] == "A")) {
//Add swimmer to the list of invites
$event_standings[$current_event][] = $swimmer_info;
//Keep only the identifying information about the swimmer
$condensed_swimmer_info["name"] = $swimmer_info["name"];
$condensed_swimmer_info["year"] = $swimmer_info["year"];
$condensed_swimmer_info["team"] = $swimmer_info["team"];
//Check if swimmers name already appears in list
if (!in_array($condensed_swimmer_info, $participating_swimmers)) {
//It is a unique user - add them to the list
$participating_swimmers[] = $condensed_swimmer_info;
}
} else {
//Add the qualifying time that did not fit into the list to a list of qualifying times
$qualifying_times[$current_event][] = $swimmer_info;
}
}
}
mysql_free_result($select_times_query);
//Sort each array of times in descending order
arsort($event_standings);
arsort($qualifying_times);
$num_of_swimmers = count($participating_swimmers);
$sql = "SELECT DISTINCT(event)
FROM demo_times_table
WHERE sex = 'M' limit 80";
$query = mysql_query($sql);
while ($row = mysql_fetch_assoc($query)) {
$loe = $row['event'];
$num_of_qualifying_times = count($qualifying_times[$loe]);
$event_standings[$loe][] = $qualifying_times[$loe][$num_of_qualifying_times-1];
//Keep only the identifying information about the swimmer
$condensed_swimmer_info["name"] = $qualifying_times[$loe][$num_of_qualifying_times]["name"];
$condensed_swimmer_info["year"] = $qualifying_times[$loe][$num_of_qualifying_times]["year"];
$condensed_swimmer_info["team"] = $qualifying_times[$loe][$num_of_qualifying_times]["team"];
//Check if swimmers name already appears in list
if (!in_array($condensed_swimmer_info, $participating_swimmers)) {
//It is a unique user - add them to the list
$participating_swimmers[] = $condensed_swimmer_info;
}
//Remove time from array of qualifying times
unset($qualifying_times[$loe][$num_of_qualifying_times-1]);
}
$num_of_swimmers = count($participating_swimmers);
mysql_free_result($query);
arsort($event_standings);
arsort($qualifying_times);
$sql = "SELECT DISTINCT(event)
FROM demo_times_table
WHERE sex = 'M'";
$query = mysql_query($sql);
while ($row = mysql_fetch_assoc($query)) {
$loe = $row['event'];
echo "<h1>".$loe."</h1><br />";
foreach ($event_standings[$loe] as $es) {
echo $es["time"]." ".$es["name"]." ".$es["team"]."<br />";
}
}
/*
foreach ($participating_swimmers as $ps) {
echo $ps["name"]."<br /><br />";
}
echo "<br /><br />";
*/
?>
关于php - 耗尽内存 - 尝试修复循环,仍然不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4945641/
我们认为 Cloud Foundry 中的一组虚拟机存在 Azure SNAT 耗尽问题。这些机器不经过负载平衡器。 我已经浏览过这份文件: https://learn.microsoft.com/e
我正在使用 onSceneTouchEvent 在 TMX map 上移动玩家: @Override public Scene onCreateScene() { ...
关于这篇文章:Python del Statement , 我最近遇到了以下片段: # custom_process.py import threading import subprocess myL
我有一个具有多个线程的 python 应用程序,其中线程 2 到 n 可能会打开任意数量的文件。我想确保当线程 1 尝试打开文件时,它绝对不会因为文件描述符耗尽而失败。简而言之,我想保留文件描述符而不
我开发了一个 c# .net 4 应用程序,它每天对组织中的每台计算机(超过 70,000 台)执行 WMI 查询。由于与此线程无关的原因,我无法从服务器运行该应用程序,而是从我的 Windows X
我正在尝试在 pytorch 中实现 Yolo-v2。但是,我似乎只是通过网络传递数据而耗尽了内存。该模型很大,如下所示。但是,我觉得我在用我的网络做一些愚蠢的事情(比如不在某处释放内存)。网络在 c
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
我在这里查看了几个与“太多客户”相关的主题,但仍然无法解决我的问题,所以我必须针对我的具体情况再次询问。 基本上,我设置了本地 Postgres 服务器并需要进行数万次查询,所以我使用了 Python
我正在使用 std::random_device 并想检查它的剩余熵。根据 cppreference.com: std::random_device::entropy double entropy()
我有以下 docker-compos.yml 文件: web: build: . ports: - "4200:4200" - "35729:35729" vo
如果 Linux 操作系统用完进程 ID 会怎样?是否会删除较旧的进程以释放空间以适应 future 的请求? 最佳答案 我假设您问的是达到进程限制时会发生什么。在这种情况下,系统不允许创建新进程,直
我们将 Azure SQL 用作单个数据库并在 DTU 定价模型下使用。我们有一个包含约 50M 条记录的表,我们想在单个字符串属性上添加一个新的非聚集索引。 问题是这是一个生产数据库。如果我使用简单
我们有多个服务总线监听器在应用服务内作为连续的 Azure Webjobs 运行。总共有 12 个监听器 Web 作业在同一个 S1 应用服务计划上运行。环境很小,每天总共大约有~1000-10000
Der Azure 网络专家, 我们的 Web 应用程序经常耗尽出站 TCP 连接。大多数出站连接实际上是 Azure 内部连接(SQL、BlobStore、后端服务)。但我们还没有虚拟网络和专用端点
我下载了一个简单的静态网络服务器的源代码 http://www.ibm.com/developerworks/systems/library/es-nweb/sidefile1.html 但是,我对第
我已经查看了有关 SO 的其他类似问题,但无法很好地将所有内容拼凑在一起。我有一个 Rails 应用程序(在 Heroku 上),它使用具有多进程和多线程的 Puma。我的应用程序还使用 Redis
在此代码中,如果我对 ParseForm() 调用进行注释,请求将按预期工作 package main import ( "fmt" "net/http" "net/url"
我不明白。 XSLX 表大约有 3MB 大,但即使是 1024MB 的 RAM 也不足以让 PHPExcel 将其加载到内存中吗? 我这里可能做错了什么: function ReadXlsxTable
我已配置 CachingConnectionFactory包装了一个 MQTopicConnectionFactory和 MQQueueConnectionFactory每个缓存大小设置为 10。 这
我正在检查 CodeEval 中的一些问题并在 PHP 中遇到这个奇怪的错误。我没有用其他语言遇到过这样的事情,所以我不知道为什么会发生这种情况。不包括整个答案(请不要帮我找到解决方案,除了 PHP
我是一名优秀的程序员,十分优秀!