Archive for October, 2010

Found easy example for memcached with php and mysql

Just wanted to share that, and will try it next week when back at work:
Memcached example

Hope it gets me little performance boost, or at least less load on the server.

Advertisements

Leave a comment

Openstreetmap tiles over https with openlayers and server redirect

Good news: Redirect from https to http works for tiles with openlayers. This prevents mixed mode warning in Internet Explorer

I recently got some problems on a https site. I included a map from openstreetmap.org and the Internet Explorer started complaining about mixed content. Btw. it is very annoying, that for IE7 you have to click YES on the dialog, and for IE8 you have to click NO.

The openlayers javascript files come from my https server so they are no problem. The only remaining reason for this were that the tiles coming from the openstreetmap server over http. After some tries with proxying the tiles over a php script, which was too slow, finally the solution was so easy.
Writing a little tiles.php which just redirects to openstreetmap instead of proxying, and complaints from IE stopped, as the tiles.php is on the https site:

$x = intval($_GET['x']);
$y = intval($_GET['y']);
$z = intval($_GET['z']);
$r = strip_tags($_GET['r']);
if(empty($r)) $r="mapnik";
$server = array();
switch ($r) {
    case 'mapnik':
        $server[] = 'a.tile.openstreetmap.org';
        $server[] = 'b.tile.openstreetmap.org';
        $server[] = 'c.tile.openstreetmap.org';

        $url = 'http://' . $server[array_rand($server)];
        $url .= "/" . $z . "/" . $x . "/" . $y . ".png";
        break;

    case 'osma':
    default:
        $server[] = 'a.tah.openstreetmap.org';
        $server[] = 'b.tah.openstreetmap.org';
        $server[] = 'c.tah.openstreetmap.org';

        $url = 'http://' . $server[array_rand($server)] . '/Tiles/tile.php';
        $url .= "/" . $z . "/" . $x . "/" . $y . ".png";
        break;
}

header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");
exit();

The openlayers layer now just has to point to this little redirection and everything is fine:

layerMapnik = new OpenLayers.Layer.OSM("Mapnik","tiles.php?z=${z}&x=${x}&y=${y}&r=mapnik");

Inspired by http://wiki.openstreetmap.org/wiki/ProxySimplePHP

, ,

25 Comments

%d bloggers like this: