Posts Tagged ‘言支’

WEB页面多语言支持解决方案

星期二, 06月 3rd, 2008

首先建立语言档,在项目中加入.resx文件
例如:
message.zh-cn.resx ‘简体中文
message.zh-tw.resx ‘繁体中文
message.en ‘英文
…………..
=========================================
然后利用Name –Value 键值对 填入您要在页面上显示de语言
如:
name value
message.zh-cn.resx中:
res_loginbname 登陆名 :
message.zh-tw.resx中:
res_loginbname 登陸名 :
message.zh-cn.resx中:
res_loginbname Login Name :

=========================================
然后在Golbal.asax中加入多语言设定支持相关代码(浏览器需要支持Cookie)

‘=========================================
‘ Application_BeginRequest Event

‘ The Application_BeginRequest method is an ASP.NET event that executes
‘ on each web request into the portal application.

‘ The thread culture is set for each request using the language
‘ settings

‘=========================================
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
Try
If Not Request.Cookies(”resource”) Is Nothing Or Request.Cookies(”resource”).Value = “” Then
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.Cookies(”resource”).Value)
Else
Thread.CurrentThread.CurrentCulture = New CultureInfo(ConfigurationSettings.AppSettings(”DefaultCulture”))
End If
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
Catch ex As Exception
Thread.CurrentThread.CurrentCulture = New CultureInfo(ConfigurationSettings.AppSettings(”DefaultCulture”))
End Try
End Sub ‘Application_BeginRequest

在Web.Config中加入如下相关代码,用于设定编码和默认语种,在Global.asax中有调用:

=========================================
<globalization requestEncoding=”utf-8″ responseEncoding=”utf-8″ />
<appSettings>
<add key=”DefaultCulture” value=”zh-cn” />
<!– zh-cn:簡體中文 zh-tw:繁體中文 en:英文 –>
</appSettings>

=========================================
页面相关代码中使用多语言支持:

Imports System.Resources

Public Class 类名
Inherits System.Web.UI.Page
Protected LocRM As ResourceManager = New ResourceManager(”项目文件名.message”, GetType(类名).Assembly)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblLogin.Text = LocRM.GetString(”res_login”)
End Sub
End Class


=========================================

到这里多语言支持de工作就作完了,接下来自己去慢慢Key
message.zh-cn.resx ‘简体中文
message.zh-tw.resx ‘繁体中文
message.en ‘英文

这几个语言档吧

在Zeus Web Server中安装PHP语言支持

星期一, 06月 2nd, 2008

前言
Zeus是一个运行于Unix下de非常优秀deWeb Server,而PHP则是Unix下一个非常优秀de后台脚本语言. 这两个产品都是为非常喜欢de产品.为什么要写这样de一个Howto呢?是因为有大量de网站脚本是使用PHP开发de, 而这些程序运行在Zeus下也是一个非常好de选择.写这份文档de目de在于能让大家dePHP系统良好de运行于Zeus服务器上.
很早de时候我写过一份整合Zeus和PHPde文章,它主要是讲如何将PHP以FastCGIde本地调用方式来运行于Zeus中de, 本份Howto主要是来讲如何让PHP运行于Remote Responders方式下.因为这样会比以local方式有更高de可扩展性和运行效率.

准备工作
首先您应该Zeus安装完成,也不会过多de讲如何安装和配置Zeus服务器本身,因为它de安装和配置实在是太简单了.
如果有可能,最好将ports使用cvsup来升级一下.
对于PHP依赖de相关软件如果能提前装,则从ports中安装好.如MySQL、GD等. 安装fastcgi
注意,如果您安装dePHPde版本会低于4.3.0哪么您才需要这步.新dePHP版本已经内置了fastcgide库.安装fastcgide方法非常de简单:

root@~$cd /usr/ports/www/fcgi/
root@/usr/ports/www/fcgi$make;make install;make clean
编译完成后我可以在/usr/local/lib目录中看到有libfcgi.a文件,同时在/usr/local/include目录中会有fastcgide所有头文件.

编译PHP
编译PHP可以使用通常dePHP编译选项,下面是我使用de一个配置:

./configure –prefix=/usr/local/php –enable-fastcgi –with-mysql=/usr/local
需要注意de是在PHP 4.3.0以上版本是使用de –enable-fastcgi 选项,而PHP 4.3.0以前de版本应使用–with-fastcgi参数.
接着就是安装PHP到系统中:
make
make install
编译完成后,我来测试一下安装dephp是能正确运行:

root@~$cd /usr/local/php/bin/
root@/usr/local/php/bin$./php
这时将进入php相关代码输入状态,输入

<? phpinfo(); ?>
按ctrl-d运行后会见到php返回de信息则为正确.

配置FastCGI/PHP
配置FastCGI
进入Zeus管理控制台,打开需要配置deVHost配置.进入 API Support 中de FastCGI 设置.在其中设置:
Enabling Support for FastCGI Programs : Enable
在Configuring FastCGI Remote Responders中设置:
Directory name : /usr/local/php/bin/php
Location: Machine name: localhost
Additional methods supported?:None
如果您dePHP应用不在本机,即使PHP没有安装在本机上,哪么也要设置 Docroot path 参数,它可以不存在于相应de目录下.
都设置完成后,点击 Apply 按钮. 配置PHP解析指向
进入 URL Handling 中de Handlers 设置.在 Adding a Handler 中设置以下参数:

File Extension : php
Specify the path and filename of the handler, relative to the document root : /usr/local/php/bin/php
HTTP 404 errors are handled by : The handler
注意,这里de Specify the path and filename of the handler, relative to the document root 应和您上一步设置de Directory name 值相同.
都设置完成后,点击 Apply 按钮.
所有de设置完成后使用vhostdecommit功能将更 改提交并应用.这样Zeus就设置好了Fastcgi和PHPde相关参数.

配置FastCGI/PHP启动
在Zeusderc.d目录中新建一个S05phpde文件,内容为:

#!/bin/sh

# Script to start and stop the persistent PHP runner for FastCGI.
# Please check paths before use.

# FastCGI PHP binary
FPHPBIN=/usr/local/php/bin/php

# Location to place semaphore
SEMFILE=/tmp/php.pid
PHP_FCGI_CHILDREN=100
PHP_FCGI_MAX_REQUESTS=1000
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS

# This is Linux - use /proc to increase the local (ephemeral) port range
#echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range

if [ -z "$ZEUSHOME" ]
then
cd `dirname $0`/..
ZEUSHOME=`pwd`
export ZEUSHOME
fi

case “$1″ in
’start’)

if [ -e $SEMFILE ]
then
echo FastCGI PHP error: already running.Restart FastCGI PHP now
kill `cat $SEMFILE`
sleep 5
fi

if [ ! -x $FPHPBIN ]
then
echo FastCGI PHP error: please check that $FPHPBIN is executable and exists.
exit 1
fi

echo Starting FastCGI PHP.
$ZEUSHOME/web/bin/fcgirunner –user=65534 –group=65534 –pidfile=$SEMFILE 8002 $FPHPBIN
;;

’stop’)
if [ -e $SEMFILE ]
then
echo Stopping FastCGI PHP.
kill `cat $SEMFILE`
rm $SEMFILE
exit 0
fi
‘restart’)
if [ -e $SEMFILE ]
then
echo Stopping FastCGI PHP.
kill `cat $SEMFILE`
sleep 5
fi
echo Starting FastCGI PHP.
$ZEUSHOME/web/bin/fcgirunner –user=65534 –group=65534 –pidfile=$SEMFILE 8002 $FPHPBIN
*)
echo “usage: $0 {start|stop|restart}”
;;

esac
exit 1

在这个脚本中有以下内容需要视系统情况而 修改:

FPHPBIN=/usr/local/php/bin/php 应设置为phpde路径
SEMFILE=/tmp/php.pid 生成php.pidde路径,该目录必须可写
PHP_FCGI_CHILDREN=100 php进程数目
PHP_FCGI_MAX_REQUESTS=1000 每个phpde进程在退出前能够响应de请求数,用于释放资源 上面两个根据硬件配置和网站访问量设置,默认值是8,500. 一般来说 PHP_FCGI_CHILDREN > 访问并发最大值 10
PHP_FCGI_MAX_REQUESTS 如果设置过小,访问量大de网站会因为php进程重起频繁增加负荷.
#echo 1024 65000 > /proc/sys/net/ipv4/ip_local_port_range 只用于linux
–user=65534 –group=65534 为php进程运行de用户和组,一般设置为nobody用户和组FreeBSD是65534/65534,Linux是99/99
最后,将S05php文件设置为可执行文件,并将FastCGI/PHP运行起来:

chmod 755 S05php
./S05php start
一但启动后就会在ps -ax列表中显示出PHP_FCGI_CHILDREN 1个php进程.
到您devhost对应deDocroot目录中建一个info.php文件,内容为:
<?
phpinfo();
?>
使用浏览器访问vhost中deinfo.php文件,应该就可以看到PHPdeinfo页面了.

附注
感谢CCFde坛主hunreal写出deS05php脚本,它真de非常好用!
如果还有什么想了解de可以到 Zeus PHP支持 页得到更多de信息.

注:任何转载或摘抄请注明文章出处(中文FreeBSD用户组 http://www.cnfug.org)