Page 1 of 1

Blank page - child exit on bus error

Posted: Tue Aug 26, 2003 8:00 am
by timj
Hi everybody,


I'm quite new to PHP and am experiencing a very difficult problem.
After our sysadmins upgraded the Apache webserver (from 1.x to 2.x) and PHP to PHP4,
one of my php scripts no longer works.

What is even more annoying, is that I don't even get an error message (as usual), but just a blank page. When I looked at the Apache log, it mentions "child exit - bus error" (at first also child exit on segmentation fault, but now it's a bus error). I've tried to implement the error handler and output handler written by WebKreator, but with no luck.

As I'm completely stuck right now and because my site is an important one, I'd appreciate any help or input. I'd like to fix the errors or at least some clues as to identify what is going on.

So, PLEASE help me!

It also seems that the substr() function does not always work as it should. In some cases it works and in others it doesn't. But I'm not sure that this causes the blank page and child error.

The code of the script is as follows:
$month=array("Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec");

$id=getMyPid();
/*Read all filenames of maps*/
$Maps=file("tmp/Map_$REMOTE_HOST");
/*Count the number of maps*/
$nMaps=count($Maps);
/*define JavaScript arrays*/
print("myImages=new Array;\n");
print("titleArray=new Array;\n");
print("legendArray=new Array;\n");

/*include the legend array, which defines the color bar you need to use for each map*/
require 'scales.php'; /*this pastes the scales.php file into the HTML code of the site. Instead, we want the lines of scales.php to be executed here*/
/*You will need to enclose the code in scales .php inside the php tags (<? and ?>), so that the php code, pasted in the html code, is again treated as php code*/

/*test 4th character in map's URL (M in MapsM/..., D in MapsD1 or MapsD3)*/
/*NOT NECESSARY FOR SO2 - only 1 projection!*/

/*loop over all maps*/
for ($i=0,$j=0;$i<$nMaps;$i++)
{
$n=strlen($Maps[$i]);
/*split the i'th Maps element (string) in separate parts*/
list($mapType,$dirname,$year,$file)=explode("/",$Maps[$i]);

/*IF-TEST IS NOT NECESSARY FOR SO2: only 1 projection!*/
/*current map's projection must be same as the selected map's projection*/
/*if ($Maps[$i][$projIdx]==$proj)*/
/*{*/
/*print "framenr=" line for current map (=map that was clicked on), framenr starts the ZoomAnimation at the right frame (=element in array)*/
if ($i==$curMap)
print("framenr=".$j.";\n");

print("myImages[".$j."]='".substr($Maps[$i],0,$n-1)."';\n");

/*JE KUNT OOK $mapType gebruiken in de if-test!*/
if (substr($Maps[$i],4,1)=='M')
{
$mm=substr($Maps[$i],-7,2);
$yyyy=substr($Maps[$i],-12,4);
$datestr=$yyyy."_".$mm;
print("titleArray[".$j."]='GOME SO2, ".$month[intval($mm)-1]." ".$yyyy."';\n");
$nItem=count($legend[$mapType][$dirname]["sdate"]);
$cbfound=0;
/*DEBUG*/
/*print("ITEMS: ".$nItem."\n");*/
/*Following test proves that the file has been included/legend array exists*/
/*print("TEST: ".$legend["MapsM"]["Mexico"]["edate"][0]."\n");
print("TEST: ".$legend[$mapType][$dirname]["edate"][0]."\n");
*/

for($k=0;$k<$nItem;$k++)
{
if($legend[$mapType][$dirname]["sdate"][$k]<=$datestr && $legend[$mapType][$dirname]["edate"][$k]>=$datestr)
{
print("legendArray[".$j."]='".$legend[$mapType][$dirname]["legend"][$k]."';\n");
$cbfound=1;
}
}
if($cbfound==0)
{
/*you can give an error, specify a default file or an empty string*/
/*BEST: give a default image, otherwise ZoomAnimation might fail!*/
/*NO: might be confusing for the user, unless the color bar is clearly marked (eg with a text on it) as "unreliable" or something*/
print("legendArray[".$j."]='dynapi/ColorBars/CB_Not_Found.gif';\n");

}
}
else
{ if (substr($Maps[$i],5,1)=='1')
{
$mm=substr($Maps[$i],-10,2);
$yyyy=substr($Maps[$i],-15,4);
$datestr=$yyyy."_".$mm;
print("titleArray[".$j."]='GOME SO2, ".intval(substr($Maps[$i],-7,2))." ".$month[intval($mm)-1]." ".$yyyy."';\n");
$nItem=count($legend[$mapType][$dirname]["sdate"]);
$cbfound=0;
/*DEBUG*/
/*print("ITEMS: ".$nItem."\n");*/

for($k=0;$k<$nItem;$k++)
{
if($legend[$mapType][$dirname]["sdate"][$k]<=$datestr && $legend[$mapType][$dirname]["edate"][$k]>=$datestr)
{
print("legendArray[".$j."]='".$legend[$mapType][$dirname]["legend"][$k]."';\n");
$cbfound=1;
}
}
if($cbfound==0)
{
/*you can give an error, specify a default file or an empty string*/
/*BEST: give a default image, otherwise ZoomAnimation might fail!*/
/*NO: might be confusing for the user, unless the color bar is clearly marked (eg with a text on it) as "unreliable" or something*/
print("legendArray[".$j."]='dynapi/ColorBars/CB_Not_Found.gif';\n");
}
}
else
{
/*3-day map: "middle" day's dd is inside map's filename*/
$day1=intval(substr($Maps[$i],-7,2))-1;
$day2=intval(substr($Maps[$i],-7,2))+1;
$mm=substr($Maps[$i],-10,2);
/*DEBUG: this was used to test the indexes of substr() for $mm*/
/*print("MM: $mm MAP $Maps[$i]\n");*/
$yyyy=substr($Maps[$i],-15,4);
$datestr=$yyyy."_".$mm;
print("titleArray[".$j."]='GOME SO2, ".$day1."-".$day2." ".$month[intval($mm)-1]." ".$yyyy."';\n");
$nItem=count($legend[$mapType][$dirname]["sdate"]);
$cbfound=0;
/*DEBUG*/
/*print("ITEMS: ".$nItem."\n");*/

for($k=0;$k<$nItem;$k++)
{
if($legend[$mapType][$dirname]["sdate"][$k]<=$datestr && $legend[$mapType][$dirname]["edate"][$k]>=$datestr)
{
print("legendArray[".$j."]='".$legend[$mapType][$dirname]["legend"][$k]."';\n");
$cbfound=1;
}
}
if($cbfound==0)
{
/*you can give an error, specify a default file or an empty string*/
/*BEST: give a default image, otherwise ZoomAnimation might fail!*/
/*NO: might be confusing for the user, unless the color bar is clearly marked (eg with a text on it) as "unreliable" or something*/
print("legendArray[".$j."]='dynapi/ColorBars/CB_Not_Found.gif';\n");
}
}

}
$j++;
/*}*/
}
/*is replaced by parameter in config file (to make the legend depend on the region/volcano, because there is 1 config file for each region/volcano)*/
/*print("legend='BrO_Legend.gif';\n");*/

/*BETER: resize laten afhangen van imgSize of zo (vb resizeTo(imgWidth+200,imgHeight+150) - geef ruimte aan de buttonlayers!)*/
/*print("window.resizeTo(725,mapHeight+300); \n");*/

print("window.resizeTo(mapWidth+legendWidth+160,mapHeight+300); \n");

print("window.moveTo(10,10); \n");

Posted: Thu Aug 28, 2003 4:19 am
by timj
In hindsight, the code seems a bit much to read. But it's just the part in the big for-loop that's causing the errors. You can focus on just 1 of the 3 parts in the if-test that tests on 'M', '3' or '1'. The code is similar for the other 2 parts.

Note also that the $legendarray is loaded in via the require() of the file scales.php.


Any help at all is very welcome.


The link to the tool from WebKreator is:
http://www.webkreator.com/php/configura ... rrors.html

Posted: Thu Aug 28, 2003 4:22 am
by JayBird
can you please put php code tags around your code.

see here - viewtopic.php?t=8815

Use the bbcode tags for code blocks - for PHP code use the [syntax=php][/syntax] tags to enclose it, for all other code use the [syntax=php][/syntax] tags - this will make it much easier for people to read your code (especially if you've taken the time to indent it properly).

Posted: Thu Aug 28, 2003 4:29 am
by timj
Here is the code:

Code: Select all

<?

$month=array("Jan",
              "Feb",
              "Mar",
              "Apr",
              "May",
              "Jun",
              "Jul",
              "Aug",
              "Sep",
              "Oct",
              "Nov",
              "Dec");

 $id=getMyPid();
 /*Read all filenames of maps*/
 $Maps=file("tmp/Map_$REMOTE_HOST");
 /*Count the number of maps*/
 $nMaps=count($Maps);
 /*define JavaScript arrays*/
 print("myImages=new Array;\n");
 print("titleArray=new Array;\n");
 print("legendArray=new Array;\n");

 /*include the legend array, which defines the color bar you need to use for each map*/
 require 'scales.php'; /*this pastes the scales.php file into the HTML code of the site. Instead, we want the lines of scales.php to be executed here*/
 /*You will need to enclose the code in scales .php inside the php tags (<? and ?>), so that the php code, pasted in the html code, is again treated as php code*/

 /*test 4th character in map's URL (M in MapsM/..., D in MapsD1 or MapsD3)*/
 /*NOT NECESSARY FOR SO2 - only 1 projection!*/

 /*loop over all maps*/
 for ($i=0,$j=0;$i<$nMaps;$i++)
  {
   $n=strlen($Maps[$i]);
   /*split the i'th Maps element (string) in separate parts*/
   list($mapType,$dirname,$year,$file)=explode("/",$Maps[$i]);

   /*IF-TEST IS NOT NECESSARY FOR SO2: only 1 projection!*/
   /*current map's projection must be same as the selected map's projection*/ 
   /*if ($Maps[$i][$projIdx]==$proj)*/
   /*{*/
     /*print "framenr=" line for current map (=map that was clicked on), framenr starts the ZoomAnimation at the right frame (=element in array)*/
     if ($i==$curMap)
      print("framenr=".$j.";\n");

     print("myImages[".$j."]='".substr($Maps[$i],0,$n-1)."';\n");

     /*JE KUNT OOK $mapType gebruiken in de if-test!*/
     if (substr($Maps[$i],4,1)=='M')
     {
      $mm=substr($Maps[$i],-7,2);
      $yyyy=substr($Maps[$i],-12,4);
      $datestr=$yyyy."_".$mm;
      print("titleArray[".$j."]='GOME SO2, ".$month[intval($mm)-1]." ".$yyyy."';\n");
      $nItem=count($legend[$mapType][$dirname]["sdate"]);
      $cbfound=0;
      /*DEBUG*/
      /*print("ITEMS: ".$nItem."\n");*/
      /*Following test proves that the file has been included/legend array exists*/
      /*print("TEST: ".$legend["MapsM"]["Mexico"]["edate"][0]."\n");
      print("TEST: ".$legend[$mapType][$dirname]["edate"][0]."\n");
      */

      for($k=0;$k<$nItem;$k++)
      {
         if($legend[$mapType][$dirname]["sdate"][$k]<=$datestr && $legend[$mapType][$dirname]["edate"][$k]>=$datestr)
 	 {
         	print("legendArray[".$j."]='".$legend[$mapType][$dirname]["legend"][$k]."';\n");
		$cbfound=1;
	 }
      }
      if($cbfound==0)
      {
	/*you can give an error, specify a default file or an empty string*/
        /*BEST: give a default image, otherwise ZoomAnimation might fail!*/
	/*NO: might be confusing for the user, unless the color bar is clearly marked (eg with a text on it) as "unreliable" or something*/
	  print("legendArray[".$j."]='dynapi/ColorBars/CB_Not_Found.gif';\n");

      }
     }
     else
     { if (substr($Maps[$i],5,1)=='1')
       {
        $mm=substr($Maps[$i],-10,2);
        $yyyy=substr($Maps[$i],-15,4);
        $datestr=$yyyy."_".$mm;
        print("titleArray[".$j."]='GOME SO2, ".intval(substr($Maps[$i],-7,2))." ".$month[intval($mm)-1]." ".$yyyy."';\n");
        $nItem=count($legend[$mapType][$dirname]["sdate"]);
        $cbfound=0;
        /*DEBUG*/
        /*print("ITEMS: ".$nItem."\n");*/

        for($k=0;$k<$nItem;$k++)
        {
           if($legend[$mapType][$dirname]["sdate"][$k]<=$datestr && $legend[$mapType][$dirname]["edate"][$k]>=$datestr)
 	   {
         	print("legendArray[".$j."]='".$legend[$mapType][$dirname]["legend"][$k]."';\n");
		$cbfound=1;
	   }
        }
        if($cbfound==0)
        {
	  /*you can give an error, specify a default file or an empty string*/
          /*BEST: give a default image, otherwise ZoomAnimation might fail!*/
	  /*NO: might be confusing for the user, unless the color bar is clearly marked (eg with a text on it) as "unreliable" or something*/
	  print("legendArray[".$j."]='dynapi/ColorBars/CB_Not_Found.gif';\n");
        }
       }
       else
       {
         /*3-day map: "middle" day's dd is inside map's filename*/
         $day1=intval(substr($Maps[$i],-7,2))-1;
         $day2=intval(substr($Maps[$i],-7,2))+1;
         $mm=substr($Maps[$i],-10,2);
	 /*DEBUG: this was used to test the indexes of substr() for $mm*/
	 /*print("MM: $mm MAP $Maps[$i]\n");*/
         $yyyy=substr($Maps[$i],-15,4);
         $datestr=$yyyy."_".$mm;
         print("titleArray[".$j."]='GOME SO2, ".$day1."-".$day2." ".$month[intval($mm)-1]." ".$yyyy."';\n");
         $nItem=count($legend[$mapType][$dirname]["sdate"]);
         $cbfound=0;
         /*DEBUG*/
         /*print("ITEMS: ".$nItem."\n");*/

         for($k=0;$k<$nItem;$k++)
         {
            if($legend[$mapType][$dirname]["sdate"][$k]<=$datestr && $legend[$mapType][$dirname]["edate"][$k]>=$datestr)
 	    {
          	print("legendArray[".$j."]='".$legend[$mapType][$dirname]["legend"][$k]."';\n");
 		$cbfound=1;
 	    }
         }
         if($cbfound==0)
         {
	   /*you can give an error, specify a default file or an empty string*/
           /*BEST: give a default image, otherwise ZoomAnimation might fail!*/
	   /*NO: might be confusing for the user, unless the color bar is clearly marked (eg with a text on it) as "unreliable" or something*/
	   print("legendArray[".$j."]='dynapi/ColorBars/CB_Not_Found.gif';\n");
         }
       }

     }
     $j++;
    /*}*/
  }
 /*is replaced by parameter in config file (to make the legend depend on the region/volcano, because there is 1 config file for each region/volcano)*/
 /*print("legend='BrO_Legend.gif';\n");*/

  /*BETER: resize laten afhangen van imgSize of zo (vb resizeTo(imgWidth+200,imgHeight+150) - geef ruimte aan de buttonlayers!)*/
  /*print("window.resizeTo(725,mapHeight+300); \n");*/

  print("window.resizeTo(mapWidth+legendWidth+160,mapHeight+300); \n");

  print("window.moveTo(10,10); \n");

?>