[ka-Map-users] precache.php with ApacheDSO

Daniel Muller Daniel.Muller at geomatic.ch
Mon Jan 29 10:25:17 EST 2007


Hi all,

I'm using Ka-Map on a Debian Etch with Apache2 and PHP5.

PHP is installed as an Apache DSO. With this configuration 
php5_mapscript.so won't load with php_cli and I can't run precache.php 
as a command line script.
I followed the steps explained on 
http://ka-map.ominiverdi.org/wiki/index.php/Pre-caching_system to run 
precache.php (or precache2.php) as a web page.

In my case I had to much tiles to generate and my browser turned into 
timeout (I had more than 100'000 meta-tiles to generate).

To solve this by using precache.php and writing the tile.php call to a 
file rather than calling directly the URL. The arguments to precache.php 
are hard-coded in the file rather than passed as arguement (I was too 
lazy :-).

Once this file gereated, I call each URL seperatly with wget:

daniel at cyperus:~$ wget -i precache.url -b -O /dev/null -o precache.log

I also added to precache.php the a test to pass the correct ImageType to 
tile.php, like it is done by precache2.php

Fore those who are interested, the patch is in the attachement.


Daniel
-------------- next part --------------
--- precache.php	2007-01-29 14:37:57.000000000 +0100
+++ precache.php	2007-01-29 15:16:55.000000000 +0100
@@ -22,6 +22,7 @@
  *
  *****************************************************************************/
 
+/*
 if(!isset($argv)) {
     exit('This is a command line utility');
 }
@@ -40,11 +41,12 @@
         -s <scale>  Limit cache creation to a single scale
 
 END_USAGE;
-
+*/
 include('../include/config.php');
 if(!extension_loaded('MapScript')) {
     dl($szPHPMapScriptModule);
 }
+/*
 if($argc < 2) {
     exit($usage);
 }
@@ -52,10 +54,16 @@
 // parse arguments
 array_shift($argv);
 $tileURL = array_pop($argv);
+*/
+$tileURL = "http://".$_SERVER[HTTP_HOST].dirname($_SERVER[PHP_SELF])."/tile.php";
 if(preg_match('/^https?:\/\//i', $tileURL) != 1) {
     exit("Invalid <tile_url> : $tileURL\n" . $usage);
 }
-$argString = ' '.implode(' ',$argv).' ';
+/* Define the argString, should be passed as argument to the URL */
+$argString=' -m mymapname -f ';
+/* open the file containing the URL to the tiles to generate */
+$fp = fopen("/tmp/precache.url","w");
+
 // check for -f force option
 $forceOpt = (preg_match('/\s-f\s/', $argString) == 1) ? '&force=true' : '';
 // check for -m map option
@@ -77,7 +85,8 @@
     }
 }
 
-$allErrors = array();
+print "<pre>\n";
+//$allErrors = array();
 $inchesPerUnit = array(1, 12, 63360.0, 39.3701, 39370.1, 4374754);
 foreach($aszMapFiles as $mapKey => $mapParams) {
     $mapScales = $mapParams['scales'];
@@ -140,11 +149,17 @@
         $oMap->set("scale", $scale);
         foreach($aGroups as $groupName) {
             // determine if at least one layer in group is visible (due to scale)
+	    unset($imageformat);
             $groupIsVisible = false;
             $aLayersIdx = $oMap->getLayersIndexByGroup($groupName);
             foreach($aLayersIdx as $layerIndex) {
                 $oLayer = $oMap->getLayer($layerIndex);
                 $oLayer->set("status", MS_ON);
+		/* Check the image format of the group */
+		$imageformat = $oLayer->getMetaData('imageformat');
+		if ($imageformat == '') {
+			$imageformat = $imageformat = $oMap->imagetype;
+		}
                 if($oLayer->isVisible()) {
                     $groupIsVisible = true;
                     break;
@@ -155,10 +170,14 @@
                 print "    Group: $groupName\n";
                 for($vertInded=0; $vertInded <$nHigh; $vertInded++) {
                     for($horizIndex=0; $horizIndex < $nWide; $horizIndex++) {
-                        $theURL = $tileURL . "?s=$scale&t=" . ($metaMinY + ($vertInded * $mapHeight)) . "&l=" . ($metaMinX + ($horizIndex * $mapWidth)) . "&map=$mapKey&g=" . urlencode($groupName) . $forceOpt;
+                        $theURL = $tileURL . "?s=$scale&t=" . ($metaMinY + ($vertInded * $mapHeight)) . "&l=" . ($metaMinX + ($horizIndex * $mapWidth)) . "&map=$mapKey&g=" . urlencode($groupName) . "&i=".strtoupper($imageformat) . $forceOpt;
+			/* Write the URL to a file */
+			fwrite($fp,$theURL."\n");
+			/*
                         if(!@file_get_contents($theURL)) {
                             array_push($allErrors, "Failed to open stream: $theURL\n");
                         }
+			*/
                     }
                 }
             }
@@ -166,6 +185,10 @@
         }
     }
 }
+fclose($fp);
+
+print "</pre>\n";
+/*
 if(count($allErrors) > 0) {
     $aPlural = (count($allErrors)==1) ? '' : 's';
     print "\nTrouble:\n  " . count($allErrors) . " error$aPlural encountered\n";
@@ -181,4 +204,5 @@
         exit;
     }
 }
+*/
 ?>


More information about the ka-Map-users mailing list