phpfox全攻略

08月 13, 2007 on 11:47 pm | In php性能 | 1 Comment

phpfox是国外的一款社区软件,具有论坛,博客,相册,音乐,投票,问答,视频等功能,基于php,mysql.安装需要gd库的支持。

我拿到程序后修改的第一步:

1.修改用户接口部分。 phpfox是典型的单入口型程序和类MVC架构。具体怎么改我不加描述了,只提一下,因为phpfox把对几乎所有路径的访问全部rewrite到了index.php,所以要在.htaccess文件中加上这样的两行:

  1. Rewritecond %{REQUEST_FILENAME} !-f
  2. Rewritecond %{REQUEST_FILENAME} !-d

一共要加两次(针对1.5,1.6这两个版本)。如果没有启用rewrite,就没有这会事。用户分别是{PREFIX}_user表,如果自行进行数据整合,操作这个表就可以了。
2.汉字在显示时有问题,需要看以下这些模板:

design/./templates/default/_modules/Menu/TabbedMenu.html
design/./templates/default/_modules/Listing/ListingCreate.html
design/./templates/default/_modules/Listing/ListingCreate.html
design/./templates/default/_modules/Account/ProfileSettings.html
design/./templates/default/_modules/Account/ProfileSettings.html
design/./templates/default/_modules/Account/ProfileSettings.html
design/./templates/default/_modules/Account/ProfileSettings.html
design/./templates/default/_modules/Account/ProfileSettings.html
design/./templates/default/_modules/Account/ProfileSettings.html
design/./templates/default/_modules/Account/ProfileSettings.html
design/./templates/default/_modules/Account/ProfileSettings.html
design/./templates/default/_modules/Ads/AdsList.html
design/./templates/default/_modules/Event/Calendar.html
design/./templates/default/_modules/Event/AddForm.html
design/./templates/default/_modules/Event/AddForm.html
design/./templates/default/_modules/Event/AddForm.html
design/./templates/default/_modules/Event/AddForm.html
design/./templates/default/_modules/Event/AddForm.html
design/./templates/default/_modules/Event/FeaturedEvents.html
design/./templates/default/_modules/Event/FeaturedEvents.html
design/./templates/default/_modules/Event/EventView.html
design/./templates/default/_modules/Event/EditForm.html
design/./templates/default/_modules/Event/EditForm.html
design/./templates/default/_modules/Event/EditForm.html
design/./templates/default/_modules/Event/EditForm.html
design/./templates/default/_modules/Event/EditForm.html
design/./templates/default/_modules/Video/Main.html
design/./templates/default/_modules/Video/AjaxBox.html
design/./templates/default/_modules/Video/ModifyCategories.html
design/./templates/default/_modules/Video/ApproveVideos.html
design/./templates/default/_modules/Video/AjaxLatest.html
design/./templates/default/_modules/Video/Categories.html
design/./templates/default/_modules/Video/Browse.html
design/./templates/default/_modules/Video/View.html
design/./templates/default/_modules/Blog/NewBlogs.html
design/./templates/default/_modules/Blog/MemberBlogs.html
design/./templates/default/_modules/Blog/AddBlog.html
design/./templates/default/_modules/Blog/MyPageBlogs.html
design/./templates/default/_modules/Blog/MyPageBlogView.html
design/./templates/default/_modules/Blog/BlogList.html
design/./templates/default/_modules/Blog/BlogList.html
design/./templates/default/_modules/Blog/BlogList.html
design/./templates/default/_modules/Blog/BlogList.html
design/./templates/default/_modules/Blog/EditBlog.html
design/./templates/default/_modules/Blog/EditBlog.html
design/./templates/default/_modules/Blog/View.html
design/./templates/default/_modules/Blog/View.html
design/./templates/default/_modules/Groups/GroupForumPosts.html
design/./templates/default/_modules/Groups/NewGroups.html
design/./templates/default/_modules/Groups/GroupDetails.html
design/./templates/default/_modules/Shoutbox/Box.html
design/./templates/default/admin/language/options.html
design/./templates/default/admin/language/options.html
design/./templates/default/admin/language/options.html
design/./templates/default/admin/language/missing-options.html
design/./templates/default/admin/language/add-phrase.html
design/./templates/default/admin/language/add-phrase.html
design/./templates/default/admin/language/phrases.html
design/./templates/default/admin/language/phrases.html
design/./templates/default/admin/language/phrases.html
design/./templates/default/admin/language/add-option.html
design/./templates/default/admin/language/missing.html

里面会有<{$title|escape}>这样的句子。将”|escape”删掉即可修正汉字bug.
3.敏感词过滤:phpfox为了扩展性,是在显示时过滤的,没有这个必要。我们把显示层的过小滤去掉,然后在index.php的第一行就加上过滤(如果有post数据,将之过滤)。这样将过滤机制更改之后,CPU又节省不少。
4.未登陆用户cache层。对于未登陆用户,没必要时时都是显示最新的。又是在index.php的第一行加上过滤:如果用户未登陆且无post数据,则显示cache层的静态文件。有1%的机率更新cache.

优化之前:

Document
Path: /
Document Length: 23960 bytes
Concurrency Level: 1
Time taken for tests: 2.740130 seconds
Complete requests: 30
Failed requests: 0
Write errors: 0
Total transferred: 733950 bytes
HTML transferred: 718800 bytes
Requests per second: 10.95 [#/sec] (mean)
Time per request: 91.338 [ms] (mean)
Time per request: 91.338 [ms] (mean, ac

优化之后:

Server Software: Apache/2.2.4
Server Hostname: ***.com
Server Port:
80
Document Path: /
Document Length: 23960 bytes
Concurrency Level: 1
Time taken for tests: 0.32685 seconds
Complete requests: 30
Failed requests: 0
Write errors: 0
Total transferred: 730560 bytes
HTML transferred: 718800 bytes
Requests per second: 917.85 [#/sec] (mean)
Time per request: 1.090 [ms] (mean)
Time per request: 1.090 [ms] (mean, across
all concurrent requests)
Transfer rate: 21814.29
[Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0
0 0.0
0 0
Processing: 0 0
1.0 1 1
Waiting: 0
0 0.3
0 1
Total: 0
0 1.0
1 1

又节约了不少资源。

4。数据库结构修改:

a.phpfox_online_session,phpfox_online,phpfox_site_session的数据都不需要永久保存。直接改成内存表。

由于内存表不支持txt类型,因此将tinytxt,text类型的字段均改为varchar字段。

现在做的改动有:

phpfox_online:

user( tinytext) 改为:user(varchar(32)

page (tinytext )改为page(varchar(100)

ip(tinytext)改为(varchar(16) )

phpfox_site_session:

browser:改为varcahr(64)

host:改为varchar(32)

page:改为varchar(64)

referer:改为varchar(64).

这个改过之后我试了一下,有些字段长度还可以进一步改小,这样才能将session数据都做成内存表,速度又可以大上一层楼。
b.flashchat_templates
这个表非常搞笑,有2万条记录,好像是在”CAN I FUCK YOU”和”<srai>DO YOU WANT TO HAVE
SEX</srai>”类似的句子之间做替换。基本没用(尤其是对中文).依我的看法如果这个表能导致瓶颈,就清空掉好了。

c.flashchat_patterns
这个表巨大无比,有15万条记录。主要是英文。如果可以的话,可以给他瘦身一下。

d.mysql的连接方式为mysql_connect,这个可以修改为mysql_pconnect。视具体情况。
e.许多表没有加索引,最搞的是论坛的topic表没有给group_id这个字段加索引。真是让人郁闷。注意把数据库结构整个看一遍,挨个把屁股擦干净。

5.去掉title中的标识:

修改include/modules/Site/classes/PhpFox_ComponentSiteTitle.class.php
中,将第200行的:

198 if (App::removeBrand())

199 {

200 // $sTitle
.= ‘ (Powered by phpFoX)’;

201 }

改掉就行了。(提醒大家,phpfox不允许未付费用户去这个标识。去这个标识需要另付费75$.

好啦,现在他可以支撑1000人在线了(其实我还加装了php-apc,这个东东把php编译结果缓存起来,另外把图片等静态文件进行了分流)。

lighttpd上搞定wordpress,给出详细步聚.

06月 16, 2007 on 8:17 pm | In 未分类 | No Comments

千辛万苦,终于将博客搬家了。原来是用的edong.com的主机,现在转到了lighttpd+fastcgi上面。

第一步:导出原空间的数据。这个得用phpmyadmin来进行。注意的时,在导出数据时,由于导出来的中文有乱码,故而我先将所有text,varchar类型数据转成了blob类型 ,然后选中将“二进制区域使用十六进制显示”这一项,这样,导出的数据中就不会有显示不了的乱码什么的,有文字的地方都是0xf535acd….这样的东东。

第二步:自然是在新服务器上用mysql -u *** -p newdatabasename < export.sql 将数据库导入进去。

第三步:修改wp-config.php中数据库连接信息。

第四步:如果这时你访问时,能直接用原密码直接进入数据库,那么很幸运,你直接登陆就是了!

如果能登陆,但进入后台时,提示你无权限进入本页面,那么也很幸运,你又可以再熟悉一次安装流程了。这时很简单,把wp-config.php中的表示数据表前缀的改掉,然后再走流程安装一次。安装完后之后,记得登陆phpmyadmin把你需要的表比如wp_posts改成新的前缀名(之前你当然得删除wordpress的安装流程为你生成的对应的表)。比如,本来我的表都是带wp_的前缀,现在将table_prefix改为wp_2然后进行了安装,那么您应该把wp2_posts表删掉,然后把wp_posts改名为wp2_posts.同理,其他需要转移的表比如comments,categories等 等也要转移地过来。

在安装时,我遇到了一点小麻烦:当输入我的email进行下一步时,系统提示这是第二步,并告诉我将要进行一些建表,加载数据操作。但是不幸地是,没有告诉我新生成的密码!我找到了这一行:

  1. </p>
  2. <p>$random_password = substr(md5(uniqid(microtime())), 0, 6);</p>
  3. <p>

改成为

  1. </p>
  2. <p>$random_password="123456";<br />

然后将

  1. </p>
  2. <p>@wp_mail($admin_email,_("New wordpress blog",....)</p>
  3. <p>

注释掉。现在没有什么拦住我了。我猜想是因为新的机器上没有sendmail服务,所以导致安装进程不能进行下去。现在安装成功能,默认密码就是:123456.

最后一步:太重要了:修改永久链接,以保持和原来的url一致。如果你的博客pr不高,访问量不怎么高,那么做不做无所谓。但是从SEO角度讲,最好还是保持一致。我原来的博客的链接设置的是:

  1. </p>
  2. <p>/archives/%post_id%.html</p>
  3. <p>

但是现在是lighttpd做server,它不支持apache的.htaccess文件里写mod_rewrite规则,怎么办?

我google了一下,找到一段巨复杂的正则表达式,却仍 不管用。自己看了一下.htaccess:

  1. </p>
  2. <p>RewriteCond %{REQUEST_FILENAME} !-f<br />
  3. RewriteCond %{REQUEST_FILENAME} !-d<br />
  4. RewriteRule . /index.php [L]<br />

就是指当请求的地址不是一个文件也不是一个目录时,转向到index.php这个文件来处理,由index.php来判断、处理。okay,现在好办了,我马上在lighttpd里加了这么一段:

  1. </p>
  2. <p>server.error-handler-404= "/index.php"</p>
  3. <p>

.okay,现在重启lighttpd,一切完美!现在你的wordpress又可以像在apache下拥有mod_rewrite一样可以随意设置永久链接了!

特别感谢老覃同志的帮忙.

Apache的Mod_rewrite的配置学习笔记

04月 29, 2007 on 9:23 pm | In 未分类 | No Comments
modrewrite配置文档学习笔记:

1.环境变量:

	例子:

	SCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html
	SCRIPT_FILENAME=/u/rse/.www/index.html
	SCRIPT_URL=/u/rse/
	SCRIPT_URI=http://en1.engelschall.com/u/rse/

2:RewriteBase
	描述:设定基于目录的重写规则的Base url.
	Syntax:	RewriteBase URL-path
	Context:	directory, .htaccess
	Override:	FileInfo
	Status:	Extension
	Module:	mod_rewrite
	这个一般不太需要管它.
3.RewriteCond
	用法:	RewriteCond Teststring Pattern
	这里是Teststring里用到的一些内置变量.
	HTTP headers:	connection & request:
	HTTP_USER_AGENT
	HTTP_REFERER
	HTTP_COOKIE
	HTTP_FORWARDED
	HTTP_HOST
	HTTP_PROXY_CONNECTION
	HTTP_ACCEPT
	REMOTE_ADDR
	REMOTE_HOST
	REMOTE_PORT
	REMOTE_USER
	REMOTE_IDENT
	REQUEST_METHOD
	SCRIPT_FILENAME
	PATH_INFO
	QUERY_STRING
	AUTH_TYPE

	DOCUMENT_ROOT
	SERVER_ADMIN
	SERVER_NAME
	SERVER_ADDR
	SERVER_PORT
	SERVER_PROTOCOL
	SERVER_SOFTWARE
	TIME_YEAR
	TIME_MON
	TIME_DAY
	TIME_HOUR
	TIME_MIN
	TIME_SEC
	TIME_WDAY
	TIME
	API_VERSION
	THE_REQUEST
	REQUEST_URI
	REQUEST_FILENAME
	IS_SUBREQ
	HTTPS

	#你可以在规则前加"!"取反.
	#这是一些常见的特殊的规则。你可以使用他们来取代一些表达式:

	* 'CondPattern’ (lexicographically follows)
    * ‘=CondPattern’ (lexicographically equal)
    * ‘-d’ (is directory)  测试是否是目录.
    * ‘-f’ (is regular file) 测试是否是常规文件.
    * ‘-s’ (is regular file, with size)
    * ‘-l’ (is symbolic link)
    * ‘-F’ (is existing file, via subrequest)
    * ‘-U’ (is existing URL, via subrequest)

	你可以为规则后设置[flags]选项作为第三个参数.常见的有:
	You can also set special flags for CondPattern by appending [flags]  as the third argument to the RewriteCond  directive, where flags is a comma-separated list of any of the following flags:

	# ‘nocase|NC’ (no case)
	# ‘ornext|OR’ (or next condition)
	例如:
	RewriteCond %{REMOTE_HOST}  ^host1.*  [OR]
	RewriteCond %{REMOTE_HOST}  ^host2.*  [OR]
	RewriteCond %{REMOTE_HOST}  ^host3.*
	RewriteRule …some special stuff for any of these hosts…

	如下例:
	RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla.*
	RewriteRule  ^/$                 /homepage.max.html  [L]

	RewriteCond  %{HTTP_USER_AGENT}  ^Lynx.*
	RewriteRule  ^/$                 /homepage.min.html  [L]

	RewriteRule  ^/$                 /homepage.std.html  [L]
	用Mozilla类的浏览器访问时会带你到homepage.max.html,这里支持所有特性。用Lynx来浏览时,带你到纯文本页(homepage.min.html),默认情况下会访问一个叫homepage.std.html的页.

4.RewriteEngine:
	使用:
	RewriteEngine On|Off
	如果存在.htaccess的文件,应当显式地指明RewriteEngine On.
	因为默认情况下.htaccess的RewriteEngine项是Off的。因此如果想用.htaccess来设置rewrite,文件头一行一般都需要RewriteEngine On

5.RewriteLock:
	供rewrite-mapping程序同步使用的锁文件。
	使用:
	RewriteLock file-path

6.RewriteLog:
	设定日志文件.如果不是以”/”开头,则是指相对ServerRoot的相对路径.
	使用:
	RewriteLog	file-path

7.RewriteLogLevel:
	设定日志记录级别。
	使用:
	RewriteLogLevel level
	默认:

8.RewriteMap:
	使用Mapping.
	它的上下文是Server config 和Virtual host
	使用:
	RewriteMap Mapname MapType:Mapsource
	例如:
	在httpd.conf中配置:
	#RewriteMap exampleMap txt:/path/to/file/map.txt
	#RewriteRule ^/ex/(.*)	${exampleMap:$1}
	而map文件的格式有这个几个:
	1.txt类型的map文件:
		#Standard Plain	 txt:
		#map.txt
		#maptype:txt
		Ralf.S.Engelschall    rse   # Bastard Operator From Hell
		Mr.Joe.Average        joe   # Mr. Average

	2.Randomized Plain Text
		#maptyp:rnd
		static	www1|www2|www3|www4
		dynamic	www5|www6

		配置:
		RewriteMap servers	rnd:/path/to/mapfile/map.txt
		RewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1	[NC,P,L]
		RewriteRule ^/(.*)	http://${servers:dynamic}/$1	[P,L]

	3.dbm
		这里提供了一个txt2dmb程序。
		!/path/to/bin/perl
		##
		##  txt2dbm — convert txt map to dbm format
		##

		use NDBM_File;
		use Fcntl;

		($txtmap, $dbmmap) = @ARGV;

		open(TXT, “<$txtmap") or die "Couldn't open $txtmap!\n";
		tie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644)
		  or die "Couldn't create $dbmmap!\n";

		while () {
		  next if (/^\s*#/ or /^\s*$/);
		  $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/);
		}

		untie %DB;
		close(TXT);

		用法:
		$ txt2dbm map.txt map.db 

	4.内置函数:
		map:int map-source:internal apache functions
		functions有:toupper,tolower,escape,unescape

	5.外部程序:
		maptyp:prg map source:外部程序的路径.
		示例:
		#!/usr/bin/perl
		$| = 1;
		while () {
			# …put here any transformations or lookups…
			print $_;
		}

9.RewriteOptions
	用法:
	RewriteOptions rewriteoptions
	default	:
	rewriteoptions	maxRedirects=10
	上下文:
	server config,virtual host,.htaccess directory
	rewriteoptions可以是下面两个值:
	inherit:从上一级配置继承.
	MaxRedirects=num(10,15,,,,,等等)

10.RewriteRule:
	这是mod_rewrite中用得最多的语句了(”the real rewriting workhorse”);
	用法:
	RewriteRule pattern Substitution [Flags]

	Quantifiers:
	  ?           0 or 1 occurrences of the preceding text
	  *           0 or N occurrences of the preceding text (N > 0)
	  +           1 or N occurrences of the preceding text (N > 1)

	Grouping:
	  (text)      Grouping of text
				  (used either to set the borders of an alternative as above, or
				  to make backreferences, where the Nth group can
				  be referred to on the RHS of a RewriteRule as $N)

	Anchors:
	  ^           Start-of-line anchor
	  $           End-of-line anchor

	Escaping:
	  \char       escape the given char
				  (for instance, to specify the chars “.[]()” etc.)

	一些技巧:
   1.  back-references ($N) to the RewriteRule pattern
   2. back-references (%N) to the last matched RewriteCond pattern
   3. server-variables as in rule condition test-strings (%{VARNAME})
   4. mapping-function calls (${mapname:key|default})

	关于Flags:
	# ‘chain|C’ (chained with next rule)
	# ‘cookie|CO=NAME:VAL:domain[:lifetime[:path]]’ (set cookie)
	# ‘env|E=VAR:VAL’ (set environment variable)
	# ‘forbidden|F’ (force URL to be forbidden)
	# ‘gone|G’ (force URL to be gone)
	# ‘last|L’ (last rule)
	# ‘next|N’ (next round)
	# ‘nocase|NC’ (no case)
	# ‘noescape|NE’ (no URI escaping of output)
	例如:
	RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE]
	这将会将’/foo/zed’ 转向到’/bar?arg=p1=zed’
	# ‘nosubreq|NS’ ( not for internal sub-requests)
	# ‘proxy|P’ (force proxy)

	Note: mod_proxy must be enabled in order to use this flag.
	# ‘passthrough|PT’ (pass through to next handler)
	(例如:
	RewriteRule ^/abc(.*) /def$1 [PT]
	Alias /def /ghi

	# ‘qsappend|QSA’ (query string append)
	# ‘redirect|R [=code]‘ (force redirect)
	# ’skip|S=num’ (skip next rule(s))
	# ‘type|T=MIME-type’ (force MIME type)

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^