Hi,

i ran into a problem with mod_fcgid and i wonder whether anybody can replicate 
my problem.

There is also a bug report in here: 
http://sourceforge.net/tracker/?func=detail&aid=2854396&group_id=174879&atid=870991

Since i wrote the bug report, i did update to Apache 2.2.13, PHP 5.3.0 and 
mod_fcgid 2.2 (was 2.1 before) but the error remains (should have upgraded 
before <sigh> but that is why i write here now).

My server:
Operating systemLinux 2.6.9-023stab048.6-smp
CPUAuthenticAMD, Quad-Core AMD Opteron(tm) Processor 2352
Trying to replicate the problem just put a image.jpg file into a folder (i.e. 
800x600 pixels) and another watermark.jpg like a banner 486x60 (size does not 
matter, it should just be smaller than the original image).

Then put the following .htaccess into the same folder:

#---
RewriteEngine on
Options FollowSymlinks
RewriteBase /
AddHandler wtmrk jpg
action wtmrk /modify.php
#---


The code of the modify.php is this:

---
<?php
/*

 activeWatermark

 Free script that places watermark on images in folder

 Copyright (C) 2005 ActiveUnit.com

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

 // IMAGE WATERMARK (comment line below if you do not want to use image 
watermark)
 Define('WATERMARK_IMAGE', $_SERVER['DOCUMENT_ROOT'] . '/watermark.jpg'); // 
path to watermark image
 Define('WATERMARK_PERCENT', '50'); // Intensity of the transition (in percent)


 // TEXT WATERMARK (comment line below if you do not want to use text)
 //Define('WATERMARK_TEXT', 'Copyright (c) 2005 www.activeunit.com'); // text 
to place (image will not be used)
 Define('WATERMARK_TEXT_FONT', '3'); // font 1 / 2 / 3 / 4 / 5
 Define('TEXT_SHADOW', '1'); // 1 - yes / 0 - no
 Define('TEXT_COLOR', '#FFFFFF'); // text color 


 // GENERAL SETTINGS
 Define('WATERMARK_ALIGN_H', 'right'); // left / right / center
 Define('WATERMARK_ALIGN_V', 'bottom'); // top / bottom / center
 Define('WATERMARK_MARGIN', '10'); // margin

// 
----------------------------------------------------------------------------------------

/* ======================== FIX for switching between php4 and php5 ==== */
 if (!isset($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = 
$_SERVER['ORIG_PATH_INFO'];
 }

 $dr=preg_replace('/modify\.php.+/', '', $_SERVER['SCRIPT_NAME'] . 
$_SERVER['PATH_INFO']);
 $filename=str_replace($dr, './', $_SERVER['PATH_INFO']);
 $lst=GetImageSize($filename);
 $image_width=$lst[0];
 $image_height=$lst[1];
 $image_format=$lst[2];

if ($image_format==1) {
 // GIF format, send proper content-type and do not process
 Header("Content-Type: image/gif");
 readfile($filename);
 exit;
}
elseif ($image_format==2) {
 // JPEG format, send proper content-type and process
 Header("Content-Type: image/jpg");
 $old_image=imagecreatefromjpeg($filename);
}
elseif ($image_format==3) {
 // PNG format, send proper content-type and process
 Header("Content-Type: image/png");
 $old_image=imagecreatefrompng($filename);
}
else {
 // Show error message instead
 Header("Content-Type: text/plain");
 echo "Unknown file format: $filename";
 exit;
}

 if (Defined('WATERMARK_TEXT') && WATERMARK_TEXT!='') {
 // text

  $color = eregi_replace("#","", TEXT_COLOR);
  $red = hexdec(substr($color,0,2));
  $green = hexdec(substr($color,2,2));
  $blue = hexdec(substr($color,4,2));

  $text_color = imagecolorallocate ($old_image, $red, $green, $blue); 

  $text_height=imagefontheight(WATERMARK_TEXT_FONT);
  $text_width=strlen(WATERMARK_TEXT)*imagefontwidth(WATERMARK_TEXT_FONT);
  $wt_y=WATERMARK_MARGIN;
  if (WATERMARK_ALIGN_V=='top') {
   $wt_y=WATERMARK_MARGIN;
  } elseif (WATERMARK_ALIGN_V=='bottom') {
   $wt_y=$image_height-$text_height-WATERMARK_MARGIN;
  } elseif (WATERMARK_ALIGN_V=='center') {
   $wt_y=(int)($image_height/2-$text_height/2);
  }

  $wt_x=WATERMARK_MARGIN;
  if (WATERMARK_ALIGN_H=='left') {
   $wt_x=WATERMARK_MARGIN;
  } elseif (WATERMARK_ALIGN_H=='right') {
   $wt_x=$image_width-$text_width-WATERMARK_MARGIN;
  } elseif (WATERMARK_ALIGN_H=='center') {
   $wt_x=(int)($image_width/2-$text_width/2);
  }

  if (TEXT_SHADOW=='1') {
   imagestring($old_image, WATERMARK_TEXT_FONT, $wt_x+1, $wt_y+1, 
WATERMARK_TEXT, 0);
  }
  imagestring($old_image, WATERMARK_TEXT_FONT, $wt_x, $wt_y, WATERMARK_TEXT, 
$text_color);

 } 
 
 if (Defined('WATERMARK_IMAGE') && WATERMARK_IMAGE!='' && 
file_exists(WATERMARK_IMAGE) &&  ($image_width > 200)) {
 // image


 $lst2=GetImageSize(WATERMARK_IMAGE);
 $image2_width=$lst2[0];
 $image2_height=$lst2[1];
 $image2_format=$lst2[2];
 
 if ($image2_format==2) {
  $wt_image=imagecreatefromjpeg(WATERMARK_IMAGE);
 } elseif ($image2_format==3) {
  $wt_image=imagecreatefrompng(WATERMARK_IMAGE);
 }

  if ($wt_image) {

   $wt_y=WATERMARK_MARGIN;
   if (WATERMARK_ALIGN_V=='top') {
    $wt_y=WATERMARK_MARGIN;
   } elseif (WATERMARK_ALIGN_V=='bottom') {
    $wt_y=$image_height-$image2_height-WATERMARK_MARGIN;
   } elseif (WATERMARK_ALIGN_V=='center') {
    $wt_y=(int)($image_height/2-$image2_height/2);
   }

   $wt_x=WATERMARK_MARGIN;
   if (WATERMARK_ALIGN_H=='left') {
    $wt_x=WATERMARK_MARGIN;
   } elseif (WATERMARK_ALIGN_H=='right') {
    $wt_x=$image_width-$image2_width-WATERMARK_MARGIN;
   } elseif (WATERMARK_ALIGN_H=='center') {
    $wt_x=(int)($image_width/2-$image2_width/2);
   }

   imagecopymerge($old_image, $wt_image, $wt_x, $wt_y, 0, 0, $image2_width, 
$image2_height, WATERMARK_PERCENT);
  }

 }

 if ($image_format==2) {
  imageJpeg($old_image);
 }
 if ($image_format==3) {
  imagePng($old_image);
 }


?>
---

When i use this url http://www.domain.tld/image.jpg i get this error mesage 
after updating to PHP 5.3.0 (from 5.2.6), Apache 2.2.13 (from 2.2.4) and 
mod_fcgid 2.2 (from 2.1):

---
PHP Parse error:  syntax error, unexpected '[' in 
/srv/www/vhosts/httpdocs/image.jpg on line 234
PHP Warning:  Unexpected character in input:  '' (ASCII=16) state=0 in 
/srv/www/vhosts/httpdocs/image.jpg on line 234
---

So, to me it seems the PHP parser tries to parse the content instead of the 
browser sending it with the image/jpeg (or image/jpg) header.

When i use this url http://www.domain.tld/modify.php/image.jpg the image will 
be shown with the watermark.

Any issues with the 'AddHandler' and/or 'action' statement in .htaccess 
probably?

As soon as i switch from mod_fcgid to CGI or mod_php it does work using 
http://www.domain.tld/image.jpg.

My httpd.include:
---
        <IfModule mod_fcgid.c>
        <Files ~ (\.php)>
                SetHandler fcgid-script
                FCGIWrapper /usr/bin/php-cgi5 .php
                Options +ExecCGI
                allow from all
        </Files>
        </IfModule>
---


My /etc/apache2conf.d/mod_fcgid.conf (i did only add "Passheader Authorization" 
to it but this does not make a difference, obviously...):
---
################################################################################
##
## Sample config for apache2_mod-fcgid
##
## All lines, that are commented out, reflect the default values.
##

<IfModule fcgid_module>
##
## An idle fastcgi application will be terminated after IdleTimeout seconds.
##
#IdleTimeout 300

##
## The scan interval for idle fastcgi applications in seconds.
##
#IdleScanInterval 120

##
## a fastcgi application will be terminated if handing a single request longer
## than busy timeout. Value in seconds.
##
#BusyTimeout 300

##
## The scan interval for busy timeout fastcgi applications. Value in seconds.
##
#BusyScanInterval 120

##
## The scan interval for exit pending fastcgi applications. fastcgi applications
## will be terminated within this scanning. Value in seconds.
##
#ErrorScanInterval 3

##
## The scan interval for zombie process. Value in seconds.
##
#ZombieScanInterval 3

##
PassHeader Authorization

##
##
## A fastcgi application will be terminated if lifetime expired, even no error
## is detected. Value in seconds.
##
#ProcessLifeTime 3600

##
## The directory to put the UNIX domain socket. (UNIX only)
##
SocketPath /var/lib/apache2/fcgid/

##
## The share memory file path.
##
SharememPath /var/lib/apache2/fcgid/shm

##
## The spawn-speed control score up water limit. Score increases while a process
## is spawned or terminated, and decreases as time progresses; while the score 
is
## higher than SpawnScoreUpLimit, the spawning will be held for a while. The
## higher this number is, the higher speed of the spawning can be.
##
#SpawnScoreUpLimit n (10)

##
## The weight of spawning.  This weight will be plused to the spawn-control
## score on every spawn. The higher this number is, the lower speed of spawning
## can be.
##
#SpawnScore n (1)

##
## The weight of termination. This weight will be plused to the score while
## fastcgi process terminates. The higher this number is, the lower speed of
## spawning can be.
##
#TerminationScore n (2)

##
## The max count of total fastcgi process count.
##
#MaxProcessCount n (1000)

##
## The maximum number of fastcgi application instances allowed to run for any
## one fastcgi application.
##
#DefaultMaxClassProcessCount n (100)

##
## The default environment variables before a fastcgi application is spawned.
## You can set this configuration more than once.
##
#DefaultInitEnv  env_name env_value

##
## The connect timeout to a fastcgi application. Value in seconds.
##
## Default value: 2
##
IPCConnectTimeout 10

##
## The communication timeout to a fastcgi application. Please increase this
## value if your CGI have a slow initialization or slow respond. Value in
## seconds.
##
## Default value: 5
##
IPCCommTimeout 40

##
## CGI output cache buffer size. Value in kilobytes.
##
#OutputBufferSize 64

##
## Associate .fcgi files with mod_fcgid
##
#AddHandler fcgid-script .fcgi

##
## PHP via FastCGI
##
## uncomment the following line if you want to handle php via mod_fcgid
##
#<FilesMatch "\.php$">
#    AddHandler fcgid-script .php
#    FCGIWrapper /srv/www/cgi-bin/php5 .php
#    Options +ExecCGI
#</FilesMatch>
##
</IfModule>
# End of <IfModule fcgid_module>

##
################################################################################


I would appreciate any hints as i would prefer to use mod_fcgid.

Thanks in advance,
Marcus

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Mod-fcgid-users mailing list
Mod-fcgid-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mod-fcgid-users

Reply via email to