1

I have a heat map which I use to visualize large scale GPS data with XAMPP-PHP-PostgreSQL back-end.

However, trying to visualize the GPS data of a big time interval - such as 24 hour data of 14 months - 2.4 million rows of latitude and longitude values, that is - causes my html page to crash.

I can visualize about 900.000 rows worth of data but I always get a crash for data bigger than that.

I used ini_set('memory_limit', '-1') and set_time_limit (60) to bypass the time limit and memory warnings by PHP but now I run into this Chrome browser crash problem.

What could be causing this? My PHP code that retrieves the latitude and longitude values are as following:

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);
hakre
  • 193,403
  • 52
  • 435
  • 836
sm90901
  • 245
  • 5
  • 17
  • "crash" could mean anything in this instance. –  Oct 11 '12 at 03:00
  • @Dagon to be clear, I get the "Aw, Snap!" Chrome error message – sm90901 Oct 11 '12 at 03:01
  • 1
    i don't use chrome, i don't know what that means. –  Oct 11 '12 at 03:02
  • @Dagon sorry I couldn't be of more help in terms of clarity. All I know is that the webpage crashes and issues a "something went wrong while displaying" message. – sm90901 Oct 11 '12 at 03:07
  • The thread of the tab exited. That would be as if the firefox browser just closes. – hakre Oct 11 '12 at 03:07
  • 1
    The problem is not on the server but in the browser. It's totally uninteresting what the PHP code is therefore, you need to debug your client code. – hakre Oct 11 '12 at 03:08
  • cute those chrome error's but not very helpful –  Oct 11 '12 at 03:11
  • @hakre interestingly, commenting out the console.log(serverResponse) -the JSON encoded array of coordinates- at my ajax form submit function took care of the issue – sm90901 Oct 11 '12 at 07:06
  • @sm90901: I suggest you save the json response to a file that provokes the crash and report this issue for chromium. Please see http://dev.chromium.org/for-testers/bug-reporting-guidelines and [Where can I find and submit bug reports on Google's Chrome browser?](http://stackoverflow.com/questions/40703/where-can-i-find-and-submit-bug-reports-on-googles-chrome-browser). You should be able to attach the file to the ticket. If it contains sensitive data obfuscate it. – hakre Oct 11 '12 at 09:51

1 Answers1

2

Looks like you're returning 900,000+ data points back to the browser via json and asking the browser to handle the mapping... You might not have a php problem, but a browser overload problem.

You might try only sending every other result to the browser to see if that finishes (select all from db but only return half via json)... This could tell you if the problem is with the php or browser/JavaScript

Brian Adkins
  • 657
  • 2
  • 6
  • 13
  • I was able to push some of the elements in the result array into some new array to get the same -array of array containing arrays- format of my output, json encoded it and sent to the browser. It works, I guess I need to take a look at my client side code. – sm90901 Oct 11 '12 at 03:54
  • I commented out the console.log(serverResponse) -response was the array that held the coordinates returned by the server- at the ajax form post function I wrote and the page stopped crashing. – sm90901 Oct 11 '12 at 07:04