Commit 21d5d2f163dac799070cf4e91d142b32d70f5893

Authored by Edmar Moretti
1 parent 6d9bc5cc

Otimização do programa ogc.php para carga melhor do cache

admin/admin.db
No preview for this file type
ms_configura.php
... ... @@ -219,7 +219,7 @@ buscarapida,conectarservicos,convertemapakml,cortina,editorsql,filtroarvore,geol
219 219 inseretxt,mostraexten,outputformat,perfil,tipoimagem
220 220  
221 221 */
222   -$i3geoBlFerramentas = array("carregamapa");
  222 +$i3geoBlFerramentas = array("carregamapa","saiku");
223 223 /*
224 224 Variable: $ogrOutput
225 225  
... ...
ogc.php
... ... @@ -77,12 +77,50 @@ ogc.php?tema=bioma
77 77 ogc.php?tema=/var/www/i3geo/aplicmap/geral1debianv6.map&layers=mundo
78 78  
79 79 */
80   -set_time_limit(0);
81   -ini_set('memory_limit', '512M');
82   -include_once (dirname(__FILE__)."/classesphp/sani_request.php");
  80 +include(dirname(__FILE__)."/classesphp/sani_request.php");
  81 +include(dirname(__FILE__)."/ms_configura.php");
  82 +$_GET = array_merge($_GET,$_POST);
  83 +
83 84 if(isset($_GET["BBOX"])){
84 85 $_GET["BBOX"] = str_replace(" ",",",$_GET["BBOX"]);
85 86 }
  87 +
  88 +if(isset($_GET["tema"])){
  89 + $tema = $_GET["tema"];
  90 +}
  91 +if($_GET["id_medida_variavel"] != ""){
  92 + $_GET["id_medida_variavel"] = filter_var ( $_GET["id_medida_variavel"], FILTER_SANITIZE_NUMBER_INT);
  93 +}
  94 +//
  95 +//compatibiliza variaveis
  96 +//
  97 +if(!isset($tema) && isset($_GET["layers"])){
  98 + $tema = $_GET["layers"];
  99 +}
  100 +if(!isset($tema) && isset($_GET["LAYERS"])){
  101 + $tema = $_GET["LAYERS"];
  102 +}
  103 +if(!isset($tema) && isset($_GET["LAYER"])){
  104 + $tema = $_GET["LAYER"];
  105 +}
  106 +if(!isset($tema) && isset($_GET["temas"])){
  107 + $tema = $_GET["temas"];
  108 +}
  109 +if(isset($_GET["typeName"])){
  110 + $typename = $_GET["typeName"];
  111 + if(!isset($tema)){
  112 + $tema = $typename;
  113 + }
  114 +}
  115 +if(!isset($tema) && isset($_GET["typename"])){
  116 + $tema = $_GET["typename"];
  117 +}
  118 +//
  119 +//define um nome para o mapfile caso a origem seja o sistema de metadados estatisticos
  120 +//
  121 +if(isset($_GET["id_medida_variavel"]) && $_GET["id_medida_variavel"] != ""){
  122 + $tema = "ogcmetaestat".$_GET["id_medida_variavel"];
  123 +}
86 124 if(isset($_GET["TileMatrix"])){
87 125 $_GET["WIDTH"] = 256;
88 126 $_GET["HEIGHT"] = 256;
... ... @@ -93,20 +131,30 @@ if(isset($_GET["TileMatrix"])){
93 131 $res[] = $temp;
94 132 $temp = $temp / 2;
95 133 }
96   - //$_GET["tms"] = null;
97   - $_GET["tms"] = "/wmts/".$_GET["layer"]."/".$_GET["TileMatrix"]."/".$_GET["TileCol"]."/".$_GET["TileRow"].".png";
  134 + $_GET["tms"] = "/wmts/".$tema."/".$_GET["TileMatrix"]."/".$_GET["TileCol"]."/".$_GET["TileRow"].".png";
98 135 if($_GET["TileMatrix"]."/".$_GET["TileCol"]."/".$_GET["TileRow"] == "0/0/0" || $_GET["TileCol"] == -1 || $_GET["TileRow"]== -1){
99 136 return;
100 137 }
101 138 $_GET["BBOX"] = $lon1.",".$lat1.",".$lon2.",".$lat2;
102 139 $_GET["SERVICE"] = "WMS";
103 140 $_GET["REQUEST"] = "getMap";
104   -}
105   -$_GET = array_merge($_GET,$_POST);
106   -$tema = $_GET["tema"];
107   -if($_GET["id_medida_variavel"] != ""){
108   - $_GET["id_medida_variavel"] = filter_var ( $_GET["id_medida_variavel"], FILTER_SANITIZE_NUMBER_INT);
  141 +
109 142 }
  143 +//
  144 +//verifica se a imagem existe se o cache estiver ligado
  145 +//se existir, carrega e sai
  146 +//
  147 +if(isset($_GET["tms"]) && $_GET["tms"] != "" && $_GET["DESLIGACACHE"] != "sim"){
  148 + carregaCacheImagem($cachedir,$nomeMapfileTmp,$_GET["tms"]);
  149 +}
  150 +if($_GET["DESLIGACACHE"] != "sim" && isset($_GET["Z"]) && isset($_GET["X"])){
  151 + $x = $_GET["X"];
  152 + $y = $_GET["Y"];
  153 + $z = $_GET["Z"];
  154 + carregaCacheImagem($cachedir,$nomeMapfileTmp,"/googlemaps/$tema/$z/$x/$y");
  155 +}
  156 +set_time_limit(0);
  157 +ini_set('memory_limit', '512M');
110 158 //
111 159 //caso nenhum parametros tenha sido enviado
112 160 //
... ... @@ -126,8 +174,7 @@ if(isset($_GET["outputformat"]) && $_GET["outputformat"] != ""){
126 174 $_GET["OUTPUTFORMAT"] = $_GET["outputformat"];
127 175 }
128 176 $cache = true;
129   -//require_once(dirname(__FILE__)."/classesphp/carrega_ext.php");
130   -include(dirname(__FILE__)."/ms_configura.php");
  177 +
131 178 include(dirname(__FILE__)."/classesphp/funcoes_gerais.php");
132 179  
133 180 if(isset($logExec) && $logExec["ogc"] == true){
... ... @@ -158,38 +205,6 @@ $protocolo = $protocolo[0];
158 205 $protocolo1 = strtolower($protocolo) . '://'.$_SERVER['SERVER_NAME'];
159 206 $protocolo = strtolower($protocolo) . '://'.$_SERVER['SERVER_NAME'] .":". $_SERVER['SERVER_PORT'];
160 207 $urli3geo = str_replace("/ogc.php","",$protocolo.$_SERVER["PHP_SELF"]);
161   -//
162   -//define um nome para o mapfile caso a origem seja o sistema de metadados estatisticos
163   -//
164   -
165   -if(isset($_GET["id_medida_variavel"]) && $_GET["id_medida_variavel"] != ""){
166   - $tema = "ogcmetaestat".$_GET["id_medida_variavel"];
167   -}
168   -//
169   -//compatibiliza variaveis
170   -//
171   -
172   -if(!isset($tema) && isset($_GET["layers"])){
173   - $tema = $_GET["layers"];
174   -}
175   -if(!isset($tema) && isset($_GET["LAYERS"])){
176   - $tema = $_GET["LAYERS"];
177   -}
178   -if(!isset($tema) && isset($_GET["LAYER"])){
179   - $tema = $_GET["LAYER"];
180   -}
181   -if(!isset($tema) && isset($_GET["temas"])){
182   - $tema = $_GET["temas"];
183   -}
184   -if(isset($_GET["typeName"])){
185   - $typename = $_GET["typeName"];
186   - if(!isset($tema)){
187   - $tema = $typename;
188   - }
189   -}
190   -if(!isset($tema) && isset($_GET["typename"])){
191   - $tema = $_GET["typename"];
192   -}
193 208  
194 209 //
195 210 //garante que layers possam ser especificados de diferentes maneiras
... ... @@ -478,11 +493,6 @@ else{
478 493 if($temai3geo == false){
479 494 $l->set("status",MS_OFF);
480 495 }
481   - /*
482   - if($cache == true && strtolower($l->getmetadata('cache')) == 'sim' && $tipo == '' && count($tema) == 1){
483   - carregaCacheImagem($_GET['BBOX'],$tx,$_GET['WIDTH'],$_GET['HEIGHT'],$cachedir);
484   - }
485   - */
486 496 $l->setmetadata("ows_title",pegaNome($l));
487 497 $l->setmetadata("ows_srs",$listaepsg);
488 498 $l->set("group","");
... ... @@ -689,8 +699,7 @@ else{
689 699 }
690 700 }
691 701 }
692   - //echo "<pre>".var_dump($codigosTema);exit;
693   -
  702 + //echo "<pre>".var_dump($codigosTema);exit;
694 703 foreach($codigosTema as $c){
695 704 $codigoTema = $c["tema"];
696 705 if(file_exists($locaplic."/temas/".$codigoTema.".map")){
... ... @@ -1116,6 +1125,7 @@ if(strtolower($OUTPUTFORMAT) == &quot;csv&quot;){
1116 1125 exit;
1117 1126 }
1118 1127 //echo $req->getValue(1);exit;
  1128 +ob_clean();
1119 1129 $oMap->owsdispatch($req);
1120 1130 $contenttype = ms_iostripstdoutbuffercontenttype();
1121 1131 $buffer = ms_iogetStdoutBufferBytes();
... ... @@ -1165,13 +1175,15 @@ function carregaCacheImagem($cachedir,$map,$tms){
1165 1175 $nome = str_replace(".png","",$nome).".png";
1166 1176 //TODO verificar esses cabecalhos e comparar com geoserver
1167 1177 if(file_exists($nome)){
1168   - header('Content-Length: '.filesize($nome));
  1178 + ob_clean();
  1179 + //header('Content-Length: '.filesize($nome));
  1180 + header('Cache: '.$tms);
1169 1181 header('Content-Type: image/png');
1170   - header('Cache-Control: max-age=3600, must-revalidate');
1171   - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
1172   - header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nome)).' GMT', true, 200);
1173   - $etag = md5_file($nome);
1174   - header('Etag: '.$etag);
  1182 + //header('Cache-Control: max-age=3600, must-revalidate');
  1183 + //header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
  1184 + //header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nome)).' GMT', true, 200);
  1185 + //$etag = md5_file($nome);
  1186 + //header('Etag: '.$etag);
1175 1187 readfile($nome);
1176 1188 exit;
1177 1189 }
... ... @@ -1206,11 +1218,12 @@ function salvaCacheImagem($cachedir,$map,$tms){
1206 1218 imagepng($imgc,$nome);
1207 1219 }
1208 1220 chmod($nome,0744);
1209   - header('Content-Length: '.filesize($nome));
  1221 + //header('Content-Length: '.filesize($nome));
  1222 + ob_clean();
1210 1223 header('Content-Type: image/png');
1211   - header('Cache-Control: max-age=3600, must-revalidate');
1212   - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
1213   - header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nome)).' GMT', true, 200);
  1224 + //header('Cache-Control: max-age=3600, must-revalidate');
  1225 + //header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
  1226 + //header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nome)).' GMT', true, 200);
1214 1227 readfile($nome);
1215 1228 exit;
1216 1229 }
... ... @@ -1256,19 +1269,22 @@ function renderNocacheTms(){
1256 1269 imagepng($imgc,$nomer);
1257 1270 }
1258 1271 if($i3georendermode == 0 || !isset($i3georendermode)){
1259   - header('Content-Length: '.filesize($nomer));
  1272 + ob_clean();
  1273 + //header('Content-Length: '.filesize($nomer));
1260 1274 header('Content-Type: image/png');
1261   - header('Cache-Control: max-age=3600, must-revalidate');
1262   - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
1263   - header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nomer)).' GMT', true, 200);
1264   - readfile($nomer);
  1275 + //header('Cache-Control: max-age=3600, must-revalidate');
  1276 + //header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
  1277 + //header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nomer)).' GMT', true, 200);
  1278 + readfile($nomer);
  1279 + exit;
1265 1280 }
1266 1281 if($i3georendermode == 2){
1267 1282 ob_clean();
1268   - header('Cache-Control: public, max-age=22222222');
1269   - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT');
  1283 + //header('Cache-Control: public, max-age=22222222');
  1284 + //header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT');
1270 1285 header("X-Sendfile: $nomer");
1271   - header("Content-type: image/png");
  1286 + header("Content-type: image/png");
  1287 + exit;
1272 1288 }
1273 1289 }
1274 1290 function getfeatureinfoJson(){
... ...
temas/_lbairros.map
... ... @@ -4,9 +4,9 @@ MAP
4 4 LAYER
5 5 CONNECTION "i3geosaude"
6 6 CONNECTIONTYPE POSTGIS
7   - DATA "the_geom from (select gid, st_setsrid(the_geom,4326) as the_geom,co_bairro,no_bairro,no_distr,no_municip from i3geo_metaestat.bairros limit 10/*FW*//*FW*/) as foo using unique co_bairro using srid=4326"
  7 + DATA "the_geom from (select gid, st_setsrid(the_geom,4326) as the_geom,co_bairro,no_bairro,no_distr,no_municip from i3geo_metaestat.bairros/*FW*//*FW*/) as foo using unique co_bairro using srid=4326"
8 8 METADATA
9   - "cache" "nao"
  9 + "cache" "sim"
10 10 "TIP" "no_bairro"
11 11 "CLASSE" "SIM"
12 12 "iconetema" ""
... ...
temas/_lreal.map 100644 → 100755