[Mapserver-users] mapscript and XBase cause Out of memoryerrorand/or premature endof script headers error

Jonathan W. Lowe info at giswebsite.com
Mon Jan 6 19:12:34 EST 2003


Lowell,

Thanks for your help (once again!).

I've made a little progress.  It turned out that the hosting service had a 4 MB 
memory cap on any perl scripts run from a user's local directories (i.e. my 
case).  When the sys admin raised the cap to 12 MB, one of the scripts that had 
run out of memory at 4 MB suddenly worked.  So, the source of the problem 
appears to have been this host-imposed memory limit.

The rest of the story is still not over, however.  The test script that now 
works is only a test script; the main script still fails, with a "Premature end 
of script headers" error message in the log file.  I plan to slowly add 
subroutines to the working script and see where it stops working...

To answer your question below, I had not cross-posted to a BSD list.  Now that 
the memory cap is identified, I think it's safe to consider the issue closed 
and I'll get back to the debugging, one line at a time. :-)

Again, thank you very much for your help.

Jonathan

Quoting Lowell Filak <lfilak at medinaco.org>:

> FYI: I forwarded this thread to a gentleman I know who has far more
> experience with BSD.
> The only sticky point is that it could be a little while before he replies.
> Did you happen to cross-post this to any BSD list?
> I can't claim to be any type of expert but it would appear that there is
> deffinitely a memory usage limit being imposed at some point.
> There appears to be talk about a login.conf file that has a key in it named
> memoryuse that can be used to limit the amount of memory on a per-user
> basis.
> HTH
> Lowell
> 
> The following message was sent by "Jonathan W. Lowe" <jlowe at giswebsite.com>
> on 03 Jan 2003 14:21:50 -0800.
> 
> > Adding system("unlimit"); or system("ulimit"); to the script results in
> > the following error_log entries (respectively):
> > 
> > Can't exec "unlimit": No such file or directory at
> > /usr/home/gisweb/www/cgi-bin/ms_test5.cgi line 3.
> > gd-png:  fatal libpng error: Out of Memory
> > gd-png error: setjmp returns error condition
> > 
> > Can't exec "ulimit": No such file or directory at
> > /usr/home/gisweb/www/cgi-bin/ms_test5.cgi line 3.
> > gd-png:  fatal libpng error: Out of Memory
> > gd-png error: setjmp returns error condition
> > 
> > At a command prompt on the FreeBSD system, typing "unlimit" successfully
> > calls the builtin command.  Likewise, also in the FreeBSD system,
> > opening "sh" and typing "ulimit" returns the text: "unlimited", also
> > successfully calling the builtin command.
> > 
> > But no luck when using the system call as part of a CGI-driven script.
> > 
> > Should I be forcing the perl script to run in another shell?  (Not sure
> > how I'd do that.)
> > 
> > - Jonathan
> > 
> > On Fri, 2003-01-03 at 12:32, Lowell Filak wrote:
> > > I'm thinking as a quick test you could do:
> > > system("ulimit");
> > > or
> > > system("unlimit");
> > > and see if the script executes properly.
> > > Lowell
> > > 
> > > The following message was sent by "Jonathan W. Lowe"
> <jlowe at giswebsite.com> on 03 Jan 2003 11:50:56 -0800.
> > > 
> > > > Thanks, Lowell.  New discoveries...
> > > > 
> > > > The CGI module seems to be the problem.
> > > > 
> > > > The following bare-bones script works perfectly when the "#use CGI;"
> is
> > > > commented out:
> > > > 
> > > > #!/usr/bin/perl -w
> > > > use strict;
> > > > BEGIN { unshift(@INC, ('/usr/home/gisweb/local/lib',
> > > > '/usr/home/gisweb/local/lib/perl5/site_perl/5.005/i386-freebsd'));}
> > > > use mapscript;
> > > > use XBase;
> > > > use CGI;
> > > > 
> > > > my $mapfilename = "/usr/home/gisweb/gis/proj/berk/b20.map";
> > > > my $image_path = '/usr/home/gisweb/www/docs/gis/scratch/';
> > > > my $image_virtual_path = '/gis/scratch/';
> > > > my $image_id = $$ . time() . ".png";
> > > > 
> > > > my $map = new mapObj($mapfilename) or die('Unable to open mapfile.');
> > > > my $img = $map->draw() or die('Unable to draw map');
> > > > binmode STDOUT;
> > > > $img->saveImage($image_path .
> > > >
> $image_id,$mapscript::MS_PNG,$map->{transparent},$map->{interlace},95);
> > > > my $recnumb = 3;
> > > > my $table = new XBase '/usr/home/gisweb/gis/data/berk/wa_b.dbf'
> > > >         or die XBase->errstr;
> > > > my @querydata = $table->get_record($recnumb);
> > > > my $block_result = $querydata[1];
> > > > 
> > > > print "Content-type: text/html\n\n";
> > > > print "<html><body>\n";
> > > > print "XBase output:<br>\n";
> > > > print "$block_result!\n";
> > > > print "<p>Mapscript output:<br>\n";
> > > > print "<img src=\"$image_virtual_path";
> > > > print "$image_id\" border=\"1\">\n";
> > > > print "</body></html>\n"
> > > > 
> > > > # --- End of ms_test5.cgi --- #
> > > > 
> > > > But...when run with "use CGI;" uncommented, the image is corrupt and
> the
> > > > following message appears in the apache error_log:
> > > > 
> > > > gd-png:  fatal libpng error: Out of Memory
> > > > gd-png error: setjmp returns error condition
> > > > 
> > > > When run in the command line (as "perl ms_test5.cgi"), the program
> also
> > > > runs perfectly.
> > > > 
> > > > So, if the solution involves ulink/unlink, the shell builtin, how do I
> > > > take advantage of that builtin command if the program is running
> within
> > > > the apache/CGI environment?
> > > > 
> > > > Thanks again for your help,
> > > > 
> > > > Jonathan
> > > > 
> > > > On Fri, 2003-01-03 at 06:10, Lowell Filak wrote:
> > > > > The only thing I can seem to locate right now is the shell built-in
> command ulimit/unlimit .
> > > > > Possibly the shell that the cgi is being run in needs unlimit set.?
> > > > > All this is assuming that when you receive the out-of-memory error
> your watching top and can clearly see that there is plenty of memory left.?
> > > > > HTH
> > > > > Lowell F.
> > > > > 
> > > > > The following message was sent by "Jonathan W. Lowe"
> <jlowe at giswebsite.com> on 02 Jan 2003 16:34:07 -0800.
> > > > > 
> > > > > > List:
> > > > > > 
> > > > > > Perl mapscript in combination with the perl XBase and CGI modules
> works
> > > > > > very well in my Redhat 8 development environment, but when moving
> the
> > > > > > code to the production FreeBSD environment, the following problem
> > > > > > results:
> > > > > > 
> > > > > > A program containing the statements...
> > > > > > 
> > > > > > 	use mapscript;
> > > > > > 	use XBase;
> > > > > > 
> > > > > > ...runs the mapscript portions correctly when just the "use XBase;"
> line
> > > > > > is commented out.
> > > > > > 
> > > > > > The same program runs the XBase portions correctly when just the
> "use
> > > > > > mapscript;" line is commented out.
> > > > > > 
> > > > > > The line causing problems when both modules are running contains
> the
> > > > > > following  perl mapscript command:
> > > > > > 
> > > > > > 	my $img = $map->draw() or die('Unable to draw map');
> > > > > > 
> > > > > > The resulting line in the apache error_log reads:
> > > > > > 
> > > > > > 	Out of memory!
> > > > > > 	[Thu Jan  2 16:09:25 2003] [error] Premature end of script
> > > > > > headers...etc
> > > > > > 
> > > > > > The only posting referring to "Out of memory" in this context
> refers to
> > > > > > SWIG and is a couple of years old.
> > > > > > 
> > > > > > Any ideas for resolving this problem?
> > > > > > 
> > > > > > Regards,
> > > > > > Jonathan W. Lowe
> > > > > > 
> > > > > > _______________________________________________
> > > > > > Mapserver-users mailing list
> > > > > > Mapserver-users at lists.gis.umn.edu
> > > > > > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> > > > > 
> > > > > 
> > > > 
> > > > 
> > > > _______________________________________________
> > > > Mapserver-users mailing list
> > > > Mapserver-users at lists.gis.umn.edu
> > > > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> > > 
> > > 
> > 
> 
> 
> 


Jonathan W. Lowe
email - info at giswebsite.com
website - http://www.giswebsite.com



More information about the mapserver-users mailing list