I have created a MBTiles file from Tilemill and I am visualizing it through php MBTiles server. Its working fine. Now I want to count the loaded tiles and store it to a database. In a simple word I want to count how many tiles are loading when user is seeing the map. How can I do this?

Following is the php server code by which I am calling mbtiles

$zoom = $_GET['z'];
$column = $_GET['x'];
$row = $_GET['y'];
$db = $_GET['db'];
    // Open the database
    $conn = new PDO("sqlite:$db");

    // Query the tiles view and echo out the returned image
    $sql = "SELECT * FROM tiles WHERE zoom_level = $zoom AND tile_column = $column AND tile_row = $row";
    $q = $conn->prepare($sql);

    $q->bindColumn(1, $zoom_level);
    $q->bindColumn(2, $tile_column);
    $q->bindColumn(3, $tile_row);
    $q->bindColumn(4, $tile_data, PDO::PARAM_LOB);

    header("Content-Type: image/png");
    echo $tile_data;
  catch(PDOException $e)
    print 'Exception : '.$e->getMessage();

And using the following line to call tiles through that php file

var layer = L.tileLayer('../mbtiles.php?db=map.mbtiles&z={z}&x={x}&y={y}', {
                            tms: true,
                            maxZoom: 09,
                            minZoom: 05
  • Does the php server write access log? – user30184 Sep 5 '15 at 14:42
  • I think there is no log access written in php. How can I do that? – Devils Dream Sep 5 '15 at 17:16
  • No idea. If you had given an exact link to thing called "php MBTiles server" I would have tried to find its documentation, and if that does not help, to have a look at the source code. – user30184 Sep 5 '15 at 17:21
  • I have updated my question with codes. – Devils Dream Sep 5 '15 at 17:55
  • 1
    How about writing the log into the MBTiles database? Create a log table and insert new rows or just update tile counter with SQL // Query the tiles view and echo out the returned image and write logging info. But it may be that your web server is already logging the incoming php requests. With Apache it would go into access.log. – user30184 Sep 5 '15 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.