开发者

Incorrect encoding using PHP as Apache module

I have very specific problem running PHP as Apache 2.2 module. When running PHP as CGI, everything works OK, but slow. The output I get in this case is:

Good charset

But when runing PHP as Apache module on the same environment, I get the following output:

Wrong charset

The only difference is that I add following lines to appropriate VirtualHost in httpd.conf

SetEnv PHPRC "C:/PHP5/"
ScriptAlias /local-bin/ "C:/PHP5/"
AddHandler application/x-httpd-php5 php
Action application/x-httpd-php5 "/local-bin/php-cgi.exe"
<Directory "C:/PHP5/">
  Order allow,deny
  Allow from all
  <Files "php-cgi.exe">
    Allow from all
  </Files>
</Directory>

The website uses 2 databases - one MySQL and one MSSQL. The text which is displayed incorrectly is retrieved from MSSQL database. There aren't any problems with text which is retrieved from MySQL database. Any ideas how to run PHP as Apache module and get the same output as running PHP as CGI?

My setup is: Apache 2.2; PHP 5.2.17; mssql PHP extension 7.0; mbstring PHP extension 4.4.4

Headers in CGI mode, returned by curl -i

HTTP/1.1 200 OK
Date: Mon, 08 Aug 2011 11:56:15 GMT
Server: Apache/2.2.16 (Win32) mod_ssl/2.2.16 OpenSSL/0.9.8o
X-Powered-By: PHP/5.2.13
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=3h4kpps0l02pecfgktonq7rjd6; path=/
Transfer-Encoding: chunked
Content-Type: text/html

Headers in PHP as a module mode:

HTTP/1.1 200 OK
Date: Mon, 08 Aug 2011 12:04:16 GMT
Server: Apache/2.2.16 (Win32) mod_ssl/2.2.16 OpenSSL/0.9.8o PHP/5.2.13
X-Powered-By: PHP/5.2.13
Set-Cookie: PH开发者_Go百科PSESSID=hi9h3skbsjvpcr7usdlf36d2t7; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/html


I don't know what was the exact problem, but everything seems to work OK now. I just downloaded fresh PHP package and configured it from scratch. What I didn't mention is that I use ZendServer Community Edition and it seems to cause the problems (by the way with same PHP 5.2.17 version). When I configure virtual host to use my fresh PHP installation - everything works OK, but when I use ZendServer built in PHP it causes problems.


Any ideas how to run PHP as Apache module and get the same output as running PHP as CGI?

Normally the output does not differ because of the module type but because of configuration. Just keep the same configuration across SAPI types and you're done.

The website uses 2 databases - one MySQL and one MSSQL. The text which is displayed incorrectly is retrieved from MSSQL database.

Looks like retrieving from MSSQL fails. Check if the data is properly encoded in the database. Check the client encoding settings. This should solve your issue.


You should indicate the encoding with the content type, e.g.

Content-Type: text/html; charset=utf-8

This fixes most issues.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜