LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-22-2009, 06:18 AM   #1
Kreshna
Member
 
Registered: Oct 2006
Posts: 45

Rep: Reputation: 15
output_buffering problem: PHP page cannot load fully. Help.


EDIT: changed the title on 2009-11-23, 7.30 pm.

I have a PHP application. The application runs flawlessly on Windows version of Apache 2.2.8 and PHP 5.2.5. (part of ms4w; MapServer for Windows). I'm also using Windows XP for development purposes.

Now I have compiled Apache 2.2.14 and PHP 5.2.11 on CentOS 4.2, x86, 32-bit. My directory is /usr/local/apache2/htdocs/. My PHP directory is /usr/local/apache2/php/.

I have a PHP application named kbn-gis.php. it is stored in /usr/local/apache2/htdocs/kbn-gis/ directory.

When I have copied the application to the CentOS box, the page just refuses to load. Firefox just give me a totally blank white page, while in Opera, it takes forever to load kbn-gis.php.

It is actually a PHP MapScript (MapServer) application, but I don't think the problem is MapServer-related, because I have written small PHP pages on the CentOS box, to test the functionalities of php_mapscript.so module. Everything works fine. The small PHP pages can display vector data, raster data, and vector data stored in PostgreSQL PostGIS.

Likewise, I don't really believe there is something wrong with the CentOS' PHP. I ran phpPgAdmin (a web-based administration console for PostgreSQL), and it goes flawlessly.

What's wrong? Here's the following codes of kbn-gis.php:

Code:
<?php


	$bahasa = $_GET["lang"];
	$kawasan = $_GET["scope"];
	
	include './include/panzoom.php';
	include './include/layers.php';
	include './include/queries.php';
	include './include/general.php';

	//loading extension
	if (!extension_loaded("MapScript"))
	dl ('php_mapscript.'.PHP_SHLIB_SUFFIX);
	
	//loading map	
	switch ($kawasan) {
		case 'cakung':
			$page_name="cakung";
			$map_scope="cakung";
			$file_name="cakung";
			$page_title="Cakung";
			$bound_minx=106.909733034;
			$bound_miny=-6.153840500;
			$bound_maxx=106.952991966;
			$bound_maxy=-6.129834500;
		break;
		case 'marunda':
			$page_name="marunda";
			$map_scope="marunda";
			$file_name="marunda";
			$page_title="Marunda";
			$bound_minx=106.900757632;
			$bound_miny=-6.135184500;
			$bound_maxx=107.008910368;
			$bound_maxy=-6.075166500;
		break;
		case 'priouk':
			$page_name="priouk";
			$map_scope="priouk";
			$file_name="priouk";
			$page_title="Tanjung Priouk";
			$bound_minx=106.859465860;
			$bound_miny=-6.115590500;
			$bound_maxx=106.889916140;
			$bound_maxy=-6.098692500;
		break;
		default:
			$page_name="cakung";
			$map_scope="cakung";
			$file_name="cakung";
			$page_title="Cakung";
			$bound_minx=106.909733034;
			$bound_miny=-6.153840500;
			$bound_maxx=106.974621432;
			$bound_maxy=-6.129834500;
	}
	switch ($bahasa) {
		case 'in':
			$lang='in';
			$lang_suffix='-in';
		break;
		case 'en':
			$lang='en';
			$lang_suffix='-en';
		break;
		default:
			$lang='en';
			$lang_suffix='-en';
	}
	
	$legend = legend_lang($lang);	

	$file_suffix="map";
	$file_path="./mapfiles/";	
	$map = ms_newMapObj($file_path.$file_name.$lang_suffix.".".$file_suffix);
	
	$box = ms_newrectObj();
	$box->setextent($bound_minx, $bound_miny, $bound_maxx, $bound_maxy);
	
	//From HTML (when submitted)
	$extent_from_html = explode(" ",$_POST["current_extent"]);
	$x_map_from_html = $_POST["current_x_map"];
	$y_map_from_html = $_POST["current_y_map"];
	
	$img_click_mode=img_click_mode();
		
	active_layers($map);	
	
	map_start($map,$extent_from_html[0],$extent_from_html[1],$extent_from_html[2],$extent_from_html[3]);
		
	map_north($map,$box);		
		
	map_south($map,$box);
				
	map_west($map,$box);
		
	map_east($map,$box);	
	
	map_zoomin($map);
	
	map_zoomout($map,$box);
	
	
	//Browse atau query?
	if (isset($_POST["map_img_x"]) && isset($_POST["map_img_y"]))  {
		$x_map = x_click_to_map($map, $_POST["map_img_x"]);
		$y_map = y_click_to_map($map, $_POST["map_img_y"]);

	}
	else {
	$x_map = $x_map_from_html;
	$y_map = $y_map_from_html;	
	}		
	
	what_to_do($img_click_mode,$map,$box);
	
	$map_img=what_to_draw($img_click_mode,$map);
	$scalebar_img=$map->drawScaleBar();
	$refmap_img=$map->drawreferencemap();
	
	$map_img_url=$map_img->saveWebImage(MS_JPG,1,1,0);
	$scalebar_url=$scalebar_img->saveWebImage();
	$refmap_url=$refmap_img->saveWebImage();
	
	//To HTML
	$extent_to_html = $map->extent->minx." ".$map->extent->miny." ".$map->extent->maxx." ".$map->extent->maxy;
	$x_map_to_html = $x_map;
	$y_map_to_html = $y_map;
?>

<html>
	<head>
		<title>KBN - <?php page_title_lang($lang); echo $page_title; ?></title>
		<meta name="keywords" content="<?php echo $page_title; ?>, Sinatrix, PT. Sinatrix Indonesia, KBN, Kawasan Berikat Nusantara, Kawasan, Berikat, Nusantara, Bonded, Zone, GIS, Geographic Information System"></meta>
		<meta name="description" content="<?php page_title_lang($lang); echo $page_title; ?>"></meta>		
		<link href="./styles/stylemain.css" rel="stylesheet" type="text/css" />
		<link href="./styles/layer-drop-down.css" rel="stylesheet" type="text/css" />
		<script src="./scripts/layer-drop-down.js">
		</script>
	</head>
	<body>
			
			<table id=header border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					<td id=logo>
					</td>
					<td>
						<h1><img src="./images/decors/header-text-version-01.png"></h1>
						<h2><?php page_title_lang($lang); echo $page_title; ?></h2>
					</td>
				</tr>
			</table>
			
		<form name=<?php echo $page_name; ?> id=<?php echo $page_name; ?> method=POST ACTION=<?php echo $PHP_SELF; ?>>
			
			<table id=toolbar border="0" cellspacing="0" cellpadding="0" width="100%">
				<tr>
					<td id=button-container><?php map_scope($map_scope,$lang); ?>
					</td>					
					<td id=button-container><?php mode_dropdown($img_click_mode, $lang); ?>
					</td>
					<td align=center id=button-container>
						<?php flags($map_scope); ?>
					</td>
					<td align=center id=button-container>
						<a href="#" style="border:none">
						<img name="go_home" value="go_home" src="./images/toolbars/logo-kbn-mini.gif" style="margin-left:14px;margin-right:14px;" alt="KBN" onmouseover="this.src='./images/toolbars/logo-kbn-mini_on_mouseover.gif';" onmouseout="this.src='./images/toolbars/logo-kbn-mini.gif';" onclick="this.src='./images/toolbars/logo-kbn-mini_on_click.gif';window.open('http://www.kbn.co.id')">
						</a>
					</td>
					<td align=center id=button-container>
						<input type=image name="back" value="back" src="./images/toolbars/icon_home.gif" alt="Back" onmouseover="this.src='./images/toolbars/icon_home_on_mouseover.gif';" onmouseout="this.src='./images/toolbars/icon_home.gif';" onclick="this.src='./images/toolbars/icon_home_on_click.gif';">
					</td>
					<td align=center id=button-container>
						<input type=image name="zoomin" value="zoomin" src="./images/toolbars/icon_zoomin.gif" alt="Zoom In" onmouseover="this.src='./images/toolbars/icon_zoomin_on_mouseover.gif';" onmouseout="this.src='./images/toolbars/icon_zoomin.gif';" onclick="this.src='./images/toolbars/icon_zoomin_on_click.gif';">
					</td>
					<td align=center id=button-container>
						<input type=image name="zoomout" value="zoomout" src="./images/toolbars/icon_zoomout.gif" alt="Zoom Out" onmouseover="this.src='./images/toolbars/icon_zoomout_on_mouseover.gif';" onmouseout="this.src='./images/toolbars/icon_zoomout.gif';" onclick="this.src='./images/toolbars/icon_zoomout_on_click.gif';">
					</td>
					<td id=button-container style="width:80px;vertical-align:top">
						<input type=image name="west" value= "west" src="./images/toolbars/west.jpg" alt="pan to West" style="position:relative; top:12px; left:9px;" onmouseover="this.src='./images/toolbars/west_on_mouseover.jpg';" onmouseout="this.src='./images/toolbars/west.jpg';" onclick="this.src='./images/toolbars/west_on_click.jpg';">
						<input type=image name="north" value="north" src="./images/toolbars/north.jpg" alt="pan to North" style="position:relative; top:2px; left:9px;" onmouseover="this.src='./images/toolbars/north_on_mouseover.jpg';" onmouseout="this.src='./images/toolbars/north.jpg';" onclick="this.src='./images/toolbars/north_on_click.jpg';">									
						<input type=image name="south" value="south" src="./images/toolbars/south.jpg" alt="pan to South" style="position:relative; top:22px; left:-12px;" onmouseover="this.src='./images/toolbars/south_on_mouseover.jpg';" onmouseout="this.src='./images/toolbars/south.jpg';" onclick="this.src='./images/toolbars/south_on_click.jpg';">
						<input type=image name="east" value="east" src="./images/toolbars/east.jpg" alt="pan to East" style="position:relative; top:12px; left:-11px;" onmouseover="this.src='./images/toolbars/east_on_mouseover.jpg';" onmouseout="this.src='./images/toolbars/east.jpg';" onclick="this.src='./images/toolbars/east_on_click.jpg';">
					</td>
					
					<td  id=button-container>				
						<span id="layer-drop-down">
							<?php
								$div_id = 'd1';
								$hid_id = 'h1';
								$div_status = 'div_status';
								if ( $_POST[$div_status] == 'show' ) {
									$div_status_to_html = 'show';
									$div_style='style="visibility:visible"';
								}
								elseif ( $_POST[$div_status] == 'hidden' ) {
									$div_status_to_html = 'hidden';
									$div_style='style="visibility:hidden"';
								}
								else {
									$div_status_to_html = 'hidden';
									$div_style='style="visibility:hidden"';
								}							
							?>
							<span>
							<a href="#" onclick="mcheck('<?php echo $div_id; ?>','<?php echo $hid_id; ?>')">Layer</a><br>
								<div id="<?php echo $div_id; ?>" <?php echo $div_style; ?> >
									<b><?php									
										layer_checkboxes('cakung', $map_scope, $page_name, $lang);
										echo "<input type=hidden id=".$hid_id." name=".$div_status." value=".$div_status_to_html." >";
									?></b>
								</div>
							</span>				
							
						</span>
					</td>
					
					<td style="color:#f0f0f0">filler
					</td>
				</tr>
			</table>

			<table width="100%">
				<tr valign=top>
					<td id=mapframe>
						<input id="mapimg" name="map_img" type=IMAGE src="<?php echo $map_img_url?>" ><br>
						<input type=HIDDEN name="current_extent" value="<?php echo $extent_to_html ?>">
						<input type=HIDDEN name="current_x_map" value="<?php echo $x_map_to_html ?>">
						<input type=HIDDEN name="current_y_map" value="<?php echo $y_map_to_html ?>">
						<?php show_query_result($img_click_mode, (y_map_to_click($map, $y_map)+80), (x_map_to_click($map, $x_map)),$lang); ?>
					</td>
					<td rowspan=2>
						
						<table border=0 height=400px width=100% align=center>
							<tr>
								<td valign=top height=10px align=center>						
									<img src="<?php echo $refmap_url; ?>" >
								</td>
							</tr>
							<tr>
								<td height=100% valign=top align=center style="border-top-width:1px;border-top-color:#80A080;border-top-style:solid">
									<table style="font:12px arial" width=270px valign=top align=center border=0><tr valign=top><td valign=top>
											<?php
												echo "<b>"; echo $legend; echo "</b>"; echo "<br>"; ;
												$jml_layer = $map->numlayers;
												for ($i=0; $i<$jml_layer; $i++) {
													$layer = $map->getLayer($i);
													if ( $layer->status != MS_OFF ) {
														if ( $layer->name != 'jkt_raster' ) {
															$layer_class = $layer->getclass(0);
															$layer_name = $layer->name ;
															$layer_icon_img = $layer_class->createLegendIcon(25, 15);
															$layer_icon_url = $layer_icon_img->saveWebImage();
															echo "<img src=".$layer_icon_url." > "; echo str_replace("_"," ",$layer_name); echo "<br>";
														}
													}
												}
											?>
									</td><tr></table>
								</td>
							</tr>
							<tr>
								<td valign=bottom align=center style="border-top-width:1px;border-top-color:#80A080;border-top-style:solid">
									<?php copyright($lang);?>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr valign=bottom align=center>
					<td colspan=1>
						<img src="<?php echo $scalebar_url; ?>" >
					</td>
				</tr>
			</table>

	</form>
	</body>
</html>

Last edited by Kreshna; 11-23-2009 at 06:31 AM. Reason: it turns out to be different problem
 
Old 11-22-2009, 06:26 AM   #2
Kreshna
Member
 
Registered: Oct 2006
Posts: 45

Original Poster
Rep: Reputation: 15
Ah yes, when I do ls from PuTTy, the PHP file I unable to load (kbn-gis.php) is colored green. The PHP files I written using vi (directly on the server), which is run flawlessly on the CentOS box, is colored white. Does it matter? However, I already did "chmod 777", "chown root", and "chgrp root" on the kbn-gis.php.

The white-colored PHP files is also owned by root.
 
Old 11-22-2009, 08:58 AM   #3
Kreshna
Member
 
Registered: Oct 2006
Posts: 45

Original Poster
Rep: Reputation: 15
I have run php from cli, and apparently I got a lot of undefined indexes:
Code:
[root@kbnweb kbn-gis]# /usr/local/apache2/php/bin/php kbn-gis.php
PHP Notice:  Undefined index:  lang in /usr/local/apache2/htdocs/kbn-gis/kbn-gis.php on line 4
PHP Notice:  Undefined index:  scope in /usr/local/apache2/htdocs/kbn-gis/kbn-gis.php on line 5
PHP Warning:  Module 'MapScript' already loaded in Unknown on line 0
PHP Notice:  Undefined index:  current_extent in /usr/local/apache2/htdocs/kbn-gis/kbn-gis.php on line 81
PHP Notice:  Undefined index:  current_x_map in /usr/local/apache2/htdocs/kbn-gis/kbn-gis.php on line 82
PHP Notice:  Undefined index:  current_y_map in /usr/local/apache2/htdocs/kbn-gis/kbn-gis.php on line 83
PHP Notice:  Undefined index:  click_mode in /usr/local/apache2/htdocs/kbn-gis/include/general.php on line 54
PHP Notice:  Undefined index:  click_mode in /usr/local/apache2/htdocs/kbn-gis/include/general.php on line 54
PHP Notice:  Undefined index:  click_mode in /usr/local/apache2/htdocs/kbn-gis/include/general.php on line 57
PHP Notice:  Undefined index:  click_mode in /usr/local/apache2/htdocs/kbn-gis/include/general.php on line 57
PHP Notice:  Undefined index:  click_mode in /usr/local/apache2/htdocs/kbn-gis/include/general.php on line 60
PHP Notice:  Undefined index:  click_mode in /usr/local/apache2/htdocs/kbn-gis/include/general.php on line 60
PHP Notice:  Undefined variable: img_click_mode in /usr/local/apache2/htdocs/kbn-gis/include/general.php on line 63
PHP Notice:  Undefined index:  warehouses_and_factories in /usr/local/apache2/htdocs/kbn-gis/include/layers.php on line 11
PHP Notice:  Undefined index:  available_for_rent in /usr/local/apache2/htdocs/kbn-gis/include/layers.php on line 11
PHP Notice:  Undefined index:  facilities in /usr/local/apache2/htdocs/kbn-gis/include/layers.php on line 11
PHP Notice:  Undefined offset:  1 in /usr/local/apache2/htdocs/kbn-gis/kbn-gis.php on line 89
PHP Notice:  Undefined offset:  2 in /usr/local/apache2/htdocs/kbn-gis/kbn-gis.php on line 89
PHP Notice:  Undefined offset:  3 in /usr/local/apache2/htdocs/kbn-gis/kbn-gis.php on line 89
However, I also ran php cli on a small PHP page that I coded directly on the Linux (using vi), and I got undefined indexes as well. The difference is; this one runs without problem, while the former cannot be load at all by the browser.
Code:
[root@kbnweb kbn-gis]# /usr/local/apache2/php/bin/php test-cakung-in.php
PHP Notice:  Undefined index:  lang in /usr/local/apache2/htdocs/kbn-gis/test-cakung-in.php on line 2
PHP Notice:  Undefined index:  scope in /usr/local/apache2/htdocs/kbn-gis/test-cakung-in.php on line 3

<html>
<body bgcolor="#CCCCCC">
<center>

<H1>Test GIS Page</H1>
<P>

PHP Warning:  Module 'MapScript' already loaded in Unknown on line 0
<img src=temp/4b094c42_1fbd_0.jpeg >temp/4b094c42_1fbd_0.jpeg
</body>
</html>
Both have undefined indexes, but kbn-gis.php cannot even be loaded by the browser, while test-cakung.php runs flawlessly.

By the way, I coded kbn-gis.php on Windows, using Notepad++, while test-cakung.php was coded directly on the CentOS box, using vi. Does it matter?


Help....
 
Old 11-22-2009, 09:40 AM   #4
Kreshna
Member
 
Registered: Oct 2006
Posts: 45

Original Poster
Rep: Reputation: 15
Ah, I know that! It is a WHITE SPACE PROBLEM!!!!

I don't have a good white space remover, so I take the "dirty way" of removing white space; namely, copy paste from Notepad++ to the vi on my PuTTy window.

It solves the problem... partially. See, the page runs now, but it is only loaded partially. When I do "view source" from either Firefox or Opera, the page stops at this point:
Code:
<input type="HIDDEN" name="
instead of:
Code:
</html>
The rest of lines after <input type="HIDDEN" name=" is never processed, never displayed by any browser I tried.

It is because the whitespace, isn't it? What is the best whitespace remover, then? Thanks.

Last edited by Kreshna; 11-22-2009 at 10:08 AM.
 
Old 11-22-2009, 10:58 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Normally, if you insist on editing on MS, then uploading to linux, you'd use dos2unix, which converts the line endings.
Personally, I'd recommend finding a Linux editor you can live with and using that exclusively.
 
Old 11-23-2009, 06:28 AM   #6
Kreshna
Member
 
Registered: Oct 2006
Posts: 45

Original Poster
Rep: Reputation: 15
Thanks for the reply.

But, I just found out that copy-pasting to VI does convert the text to Linux. Thus, the problem about partially-load PHP page above is not cause by incompatible line feed.

Like I said above, the production server's never loads the page fully, ie, when showing the codes in a browser, it never reaches the closing </html> part. And it has nothing to do with bandwitdh either, I have tried browsing locally from the server itself.

I have to admit that my php page is quite large, about 9 kilobytes. It also has a lot of "echo" commands. The page also contains a lot of tab.

Recently I found out that it has something to do with output_buffering parameter in php.ini. Starting from zero, if I increase the output_buffering value, the loaded portion of my PHP page also increases. So I think if I max the output_buffering value, my PHP page will be fully loaded by the server.

Alas, that's not the case.

See, when I reach certain value, the loaded portion of the PHP page decreases again. The page reaches its biggest portion in output_buffering=1024. Increasing it to 1025, for example, doesn't change anything. But when I set it to 1210, the

Here's what happen when I set output_buffering=0. The page does not load fully, it only shows the HTML header and the toolbar.
http://i3.photobucket.com/albums/y71...ng_off_wip.jpg
output_buffering=0

At output_buffering=512, more portions of the PHP page starts to show up, evident by the code lines below the toolbar.
http://i3.photobucket.com/albums/y71...ng_512_wip.jpg
output_buffering=512

Apparently, output_buffering=1024 is the "optimum" setting, although it still fails to load the PHP page fully. The page you see below is not the full PHP page, by the way.
http://i3.photobucket.com/albums/y71...g_1024_wip.jpg
output_buffering=1024

I don't know if it is relevant, but originally, the php.ini has extension_dir = './' Problem is, I don't know what does it mean by './' (is it /usr/local/apache2/php ? is it /usr/local/apache2/lib ?). On the other hand, I need to dl php_mapscript.so into my PHP page, which I put in PHP installation prefix (/usr/local/apache2/php). So I hardcoded the extension_dir into '/usr/local/apache2/php'.

In short, what's wrong? Why the production server cannot load my PHP page fully? What should I do? Please help.
 
Old 11-23-2009, 07:11 AM   #7
Kreshna
Member
 
Registered: Oct 2006
Posts: 45

Original Poster
Rep: Reputation: 15
By the way, I forgot to mention, but I also tried using implicit_flush = On. When I use implicit_flush = On with output_buffer = 0, it works just exactly like using implicit_flush = Off with output_buffer = 1024.

However, increasing output_buffer with implicit_flush = On does not improve the situation. For example, using implicit_flush = On with output_buffer = 1024 does not fully load the PHP page either. Seems like nothing can fully load my PHP page.

What's wrong? What happens?
 
Old 11-24-2009, 03:59 AM   #8
Kreshna
Member
 
Registered: Oct 2006
Posts: 45

Original Poster
Rep: Reputation: 15
Ah, I've just found something new: the same output_buffering value does not always give consistent result.

For example, I just set output_buffering value to 3650, which showed most (alas, not the entire) of my PHP page. But about five minutes later, the same 3650 value just gave me a totally blank page (just like when I'm using output_buffering=On)

By the way, and I don't know if it's relevant, but it is a production server, which is also used by the "primary" website and a web mail server.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run PHP and Apache as root? nyheat Linux - Server 3 03-16-2008 11:55 PM
PHP: can't exec some programs when run through apache. why? BrianK Programming 3 09-20-2007 04:10 PM
Apache 2, PHP 5, SuSE 9.2 - cannot run php files dickohead Linux - Networking 6 06-28-2006 10:25 AM
How to run PHP on Apache? impulse() Linux - Software 2 05-23-2006 02:03 PM
php: exec can't run lynx after apache restart BrianK Programming 4 01-16-2006 05:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration