[Mapserver-users] SUUM: PHP undef WAS: Memory Leak?

Juanse georef@tie.cl
Wed, 29 Jan 2003 14:39:54 -0300


Daniel and the rest

I do not think the mapserver behavior could be considered as a bug since it
is basically designed for single entries over the web, and not for the
purposes we were using it (secuential mapmaking). But it would be nice if
mapserver recognices automagically to clean up the variables when it is
called again within a loop. RAM ended almost full, but the calling process
could be executed.

PHP, as we were using it, never ended and therefore it could not automagilly
clean up variables.

We follow Daniel aproach, and vuala!, we got the 2322 maps in a night (code
at the bottom).

Now the PDF part, that should be easy, and the boring printing is resting.

Thanks to all!!

Juanse
temuko-Chile
Make Wine not War! (red preferable)!

ATTACHED ARE THE PROGRAMS USED. Proyecto3(proyecto4.php).php

Proyecto3.php
<?php

set_time_limit(0);
$conexion = pg_connect("dbname=evidencia user=postgres password=pgsql");

$act = "select gid from titulosmerced_araucania where imagen is null and gid
> 0 order by gid ";
$resultado = pg_exec($conexion,$act);
for($i=0;$i<pg_num_rows($resultado);$i++) {
 $extension = pg_fetch_array($resultado,$i);
 $comando="/usr/local/apache/cgi-bin/php -q proyecto4.php
".$extension["gid"];
 passthru($comando);
}
?>

Proyecto4.php
<?php
$gid = $argv[1];
set_time_limit(0);
dl("php_mapscript.so");
function navegar(&$map,$factor,$extension,$mapa_x,$mapa_y) {
 if(is_array($extension)) {
  if(!empty($extension["minx"])
    && !empty($extension["miny"])
    && !empty($extension["maxx"])
    && !empty($extension["maxy"])
    && !empty($mapa_x)
    && !empty($mapa_y)
     ) {
   $punto = ms_newPointObj();
   $pre_ext = ms_newRectObj();

$pre_ext->setextent($extension["minx"],$extension["miny"],$extension["maxx"]
,$extension["maxy"]);
   $sal = $punto->setXY($mapa_x,$mapa_y);
   $zoom = empty($factor) ? 1 : $factor;
   $map->zoompoint($zoom,$punto,$map->width, $map->height, $pre_ext);
  }
 }
}

$conexion = pg_connect("dbname=evidencia user=postgres password=pgsql");
$map = ms_newMapObj("eviden2.map");

$act = "select xmin(the_geom) as minx, xmax(the_geom) as maxx,
ymin(the_geom) as miny, ymax(the_geom) as maxy, gid from
titulosmerced_araucania where gid=$gid ";
$resultado = pg_exec($conexion,$act);

for($i=0;$i < pg_num_rows($resultado);$i++) {
    $extension = pg_fetch_array($resultado,$i);
    $capa = $map->getLayer(15);
    $titulo = $capa->getClass(0);
    $titulo->setexpression("\"". $extension["gid"] ."\"");

    $mapa_x = $map->width / 2;
    $mapa_y = $map->height / 2;
    navegar($map,$zoom,$extension,$mapa_x,$mapa_y);
    $img1 = $map->draw();
    $url_mapa = $img1->saveWebImage(MS_PNG, 0, 0, 0);
    $img = $map->drawScaleBar();
    $url_escala = $img->saveWebImage(MS_PNG, 0, 0, 0);
    $img = $map->drawReferenceMap();
    $url_referencia = $img->saveWebImage(MS_PNG, 0, 0, 0);
/*
    $img = $map->drawLegend();
    $url_leyenda = $img->saveWebImage(MS_PNG, 0, 0, 0);
*/
    $updt = "update titulosmerced_araucania set imagen='". $url_mapa . "',
escala='". $url_escala . "', referencia='" . $url_referencia . "' where
gid=".$extension["gid"] . "\n";
    pg_exec($conexion,$updt);
    echo $updt;
}
?>


----- Original Message -----
From: Daniel Morissette <morissette@dmsolutions.ca>
To: <georef@tie.cl>; <germangutierrezg@yahoo.es>
Cc: <mapserver-users@lists.gis.umn.edu>
Sent: Friday, January 31, 2003 2:22 PM
Subject: Re: [Mapserver-users] PHP undef WAS: Memory Leak?


> Lowell Filak wrote:
> >
> > I will have to forward that request back to the list for the PHP folks
to answer.
> > Anyone who can help, please reply to germangutierrezg@yahoo.es .
> > Thank you.
> >
> > The following message was sent by "Juanse" <georef@tie.cl> on Fri, 31
Jan 2003 10:40:56 -0300.
> >
> > > yes it is, but how to undef/close/destroyed? which command it is not
in the
> > > docs.
> > >
>
> The garbage collection should happen automagically in PHP when the
> variable is overwritten or becomes out of scope... but there are always
> chances that something is not being cleaned up properly, or that some
> resources (PHP terminology for internal data structures) may not be
> registered or cleaned properly.
>
> I think this will have to be investigated further, but unfortunately we
> don't have much time for that now.  You may want to file a bug about
> this.
>
> In the meantime, you could launch a new PHP instance for each map in a
> loop using the system() call, e.g.
>
>   <?php
>     for ($i=0; $i... 2232 iterations)
>     {
>        ...
>        system("/path/to/php draw_a_map.php $map_name_and_params[$i]");
>     }
>   ?>
>
> I know this is a hack, but at least this way you'll be able to get your
> maps done and won't have to wait for a fix.  A new process will be
> started by system() for each map and you won't run into issues because
> of memory leaks.
>
> --
> ------------------------------------------------------------
>  Daniel Morissette               morissette@dmsolutions.ca
>  DM Solutions Group              http://www.dmsolutions.ca/
> ------------------------------------------------------------


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.445 / Virus Database: 250 - Release Date: 21/01/03

_______________________________________________
Mapserver-users mailing list
Mapserver-users@lists.gis.umn.edu
http://lists.gis.umn.edu/mailman/listinfo/mapserver-users