顯示包含「php」標籤的文章。顯示所有文章
顯示包含「php」標籤的文章。顯示所有文章

2009年7月25日星期六

Benchmarking php op-codes caches

1)No PHP op-code cache:

Document Path:          /cookingbama/food.php?food_id=3
Document Length:        5489 bytes

Concurrency Level:      5
Time taken for tests:   50.571265 seconds
Complete requests:      3000
Failed requests:        0
Write errors:           0
Total transferred:      17199000 bytes
HTML transferred:       16467000 bytes
Requests per second:    59.32 [#/sec] (mean)
Time per request:       84.285 [ms] (mean)
Time per request:       16.857 [ms] (mean, across all concurrent requests)
Transfer rate:          332.11 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:    30   83  47.7     73     322
Waiting:       30   81  47.3     70     322
Total:         30   83  47.7     73     322

Percentage of the requests served within a certain time (ms)
  50%     73
  66%     96
  75%    109
  80%    120
  90%    149
  95%    177
  98%    214
  99%    236
100%    322 (longest request)

2)Xcache:

Document Path:          /cookingbama/food.php?food_id=3
Document Length:        5489 bytes

Concurrency Level:      5
Time taken for tests:   4.970640 seconds
Complete requests:      3000
Failed requests:        0
Write errors:           0
Total transferred:      17199000 bytes
HTML transferred:       16467000 bytes
Requests per second:    603.54 [#/sec] (mean)
Time per request:       8.284 [ms] (mean)
Time per request:       1.657 [ms] (mean, across all concurrent requests)
Transfer rate:          3378.84 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     2    7   4.1      7      48
Waiting:        2    7   4.1      7      47
Total:          2    7   4.1      7      48

Percentage of the requests served within a certain time (ms)
  50%      7
  66%      9
  75%     10
  80%     10
  90%     12
  95%     15
  98%     18
  99%     21
100%     48 (longest request)

3)eAccelerator

Document Path:          /cookingbama/food.php?food_id=3
Document Length:        5489 bytes

Concurrency Level:      5
Time taken for tests:   6.9865 seconds
Complete requests:      3000
Failed requests:        0
Write errors:           0
Total transferred:      17199000 bytes
HTML transferred:       16467000 bytes
Requests per second:    499.18 [#/sec] (mean)
Time per request:       10.016 [ms] (mean)
Time per request:       2.003 [ms] (mean, across all concurrent requests)
Transfer rate:          2794.57 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       9
Processing:     3    9   6.1      8      57
Waiting:        3    9   6.1      8      57
Total:          3    9   6.1      8      57

Percentage of the requests served within a certain time (ms)
  50%      8
  66%     10
  75%     12
  80%     13
  90%     18
  95%     22
  98%     26
  99%     30
100%     57 (longest request)

Xcache is the winner.

2008年12月22日星期一

PHP 繁簡字碼直接轉換

最近幾日都係度整緊字碼既事 ,UTF-8, BIG5, GB2312, GBK。 要做既係兩樣野:
  1. detect charset
  2. 簡繁轉換

總結如下:

iconv斷字
icon
到無法轉換的字時, 預設是會斷句。
可以在第2個参數加入//IGNORE
iconv("BIG5","UTF-8//IGNORE",$query);
或//TRANSLIT
iconv("BIG5","UTF-8//TRANSLIT",$query);

//TRANSLIT will raise an exception on characters it can't transliterate, however; this can be solved by using '//IGNORE//TRANSLIT' together (in that order).
也可以兩個参數一起來
iconv("BIG5","UTF-8//IGNORE//TRANSLIT",$query);

用mb_convert_encoding 的話, 但會把有問題的字換成 "?"

gb->utf8

iconv("GBK","UTF-8//ignore",$word);
iconv("GB2312","UTF-8//ignore",$word);

用GBK比GB2312好, 據說係因為GBK既字庫比較大

mb_convert_encoding

mb_convert_encoding($word,"UTF-8","BIG-5");

有以下地方要注意:
  • 参數次序跟ICONV剛好倒轉
  • "BIG5" 要換成 "BIG-5"
  • "EUC-CN"要換成"GB2312"
  • "CP936" 要換成 "GBK"

charset detecting
$encoding_list="UTF-8,BIG-5,EUC-CN";
mb_detect_encoding($word, $encoding_list);

$encoding_list為 charset 的次序

-繁簡字碼可能會誤測, 所以次序很重要

繁簡換轉

上GOOGLE搜尋一下,
如果想簡轉繁的話, 方法是 UTF-8 -> GB2312 -> BIG5 -> UTF-8, 的確是可行的, 也不用任何外部的文件。但因為BIG5和 GB2312的字庫不夠UTF-8的大, 所以總有些字會變成 "?"。
解決方法是找個 簡體的UTF-8 -> 繁體UTF-8 的MAP , 再跟據MAP直接轉換。問GOOGLE後發現好像沒有人試過這樣做, 所以就寫了個類轉換。

源碼可以這下載
http://code.google.com/p/fukidutf8t2s/