在热图上显示大规模数据会导致网页崩溃 - php

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center获取指导。

7年前关闭。

我有一个热图,用于通过XAMPP-PHP-PostgreSQL后端可视化大规模GPS数据。

但是,尝试可视化较大时间间隔的GPS数据(例如14个月的24小时数据)即240万行的经度和纬度值,即会导致我的html页面崩溃。

我可以可视化大约900.000行的数据,但是对于大于该值的数据,总会崩溃。

我使用ini_set('memory_limit', '-1')set_time_limit (60)绕过PHP的时间限制和内存警告,但现在遇到了这个Chrome浏览器崩溃的问题。

是什么原因造成的?我的PHP代码检索纬度和经度值如下:

function getPoints($dateTimeBeg,$dateTimeEnd) //getting the points 
//from the database after providing the start and end date objects
{

    global $con, $coords, $coords_array; //$coords and $coords_array are declared
//at the beginning of the php script

    $query = "SELECT lat, lon FROM mytable WHERE calltime >= '$dateTimeBeg'
    and calltime <= '$dateTimeEnd'"; 

    $res = pg_query($con, $query) or die (pg_last_error($con)); 

    if($res)//if a result exists
    {
        $num_of_rows = pg_num_rows($res);

        if($num_of_rows > 0)
        {
            while($row = pg_fetch_row($res)) //fetch results row by row
            { 
                array_push($coords,array($row[0],$row[1]));      
//push them to the $coords array
            }
            array_push($coords_array,$coords); 
            unset($coords);
//push array $coords array to $coords_array ARRAY
        }
    }
}

$coords_json = json_encode($coords_array); //encode the results as json 
echo $coords_json; //print out the data, heatmap takes the 
//coordinates and takes care of the rest
unset($coords);
pg_close($con);

参考方案

看起来您正在通过json向浏览器返回900,000多个数据点,并要求浏览器处理映射...您可能没有php问题,但是浏览器过载问题。

您可以尝试仅将其他所有结果发送到浏览器以查看是否完成(从db中选择全部,但仅通过json返回一半)...这可以告诉您问题是否出在php或浏览器/ JavaScript上

PHP getallheaders替代 - php

我正在尝试从服务器上的apache切换到nginx。唯一的问题是我在PHP脚本中使用的getallheaders()函数,该函数不适用于Nginx。我已经尝试过用户在getallheaders函数上的php站点上提供的注释,但这并不返回所有请求标头。请告诉我如何解决这个问题。我真的想切换到Nginx。 参考方案 您仍然可以使用它,但是您必须像这里一样重新定义…

PHP:将字符串拆分为字母和数字部分的最佳方法 - php

我有几个格式的字符串AA11 AAAAAA1111111 AA1111111 分离字符串的字母和数字部分的最佳方法(最有效)? 参考方案 如果它们都是一系列字母,然后是一系列数字,并且没有非字母数字字符,那么sscanf()可能比regexp更有效$example = 'AAA11111'; list($alpha,$numeric) =…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…

PHP:从函数返回值并直接回显它? - php

这可能是一个愚蠢的问题,但是……的PHPfunction get_info() { $something = "test"; return $something; } html<div class="test"><?php echo get_info(); ?></div> 有没有办…

php:是否有充分的理由引用所有数组键/索引? - php

我正在遍历别人的代码,他们总是避免转义其数组键。例如:$ row_rsCatalogsItems [名称]代替$ row_rsCatalogsItems ['名称']因此,我不断地对自己接触的所有事物进行微小的更改,以应对这些惰性。但是现在我想知道这样做是否有很多好处。我得到它会在默认为字符串之前检查常量(我在处理常量时会讨厌php中的行为,因为即使未定义,…