dsiuy42084 2011-02-16 19:07
浏览 138
已采纳

缓存模板分析器生成的页面 - 包括哈希排名

I am currently working on a template parser that takes a load of variables (including arrays) and loops though a provided template searching and replacing them with PHP, then caches this PHP and sends it to the browser.

However I would like to add another layer of caching where it caches the HTML generated by the PHP and am wondering the best way to do it and whether it would be worth it?

The only way I can think to implement this would be to md5 all the variables that the generated PHP was given and then check against a list of HTML files as to whether the variables have the same hash, however I imagine this would be very cpu intensive and a complete waste of time.

Would it be a waste of time? Is there a better way to do this?]

.

Edit: Ranked List of All PHP's Hashing Algorhythms - Generated Fairly

So I created a fair comparison of all of PHP's hashing algorithms, included here for interest.

For anyone interested here is a ranked list of PHP's hashing algorithms tested with 10000 hashes of a shared (per loop) random 15 digit number and a random 500 letter string.

I also include the possibilities that that hash has, an example of the hash and the average rank of that hash.

Hash Time Rank

1 - crc32 0.109843254089
2 - crc32b 0.112758636475
3 - md4 0.128808498383
4 - md5 0.141296863556
5 - sha1 0.151764154434
6 - adler32 0.152633905411
7 - tiger192,3 0.185636281967
8 - tiger128,3 0.192178249359
9 - ripemd128 0.192563295364
10 - tiger160,3 0.195315361023
11 - ripemd256 0.201178789139
12 - salsa10 0.211281776428
13 - tiger160,4 0.215661048889
14 - tiger192,4 0.215940475464
15 - tiger128,4 0.218608856201
16 - haval224,3 0.219294309616
17 - salsa20 0.220067501068
18 - haval192,3 0.220562696457
19 - sha256 0.221296072006
20 - haval160,3 0.221850395203
21 - ripemd320 0.223988294601
22 - ripemd160 0.224121570587
23 - sha224 0.225886106491
24 - haval256,3 0.229130744934
25 - haval128,3 0.235924243927
26 - haval256,4 0.267326116562
27 - haval160,4 0.269260883331
28 - haval224,4 0.270739555359
29 - haval128,4 0.272269487381
30 - haval192,4 0.272310495377
31 - haval224,5 0.300775766373
32 - haval160,5 0.301377296448
33 - haval192,5 0.302173137665
34 - haval256,5 0.302881002426
35 - haval128,5 0.305021524429
36 - sha384 0.365926265717
37 - sha512 0.37784910202
38 - gost 0.411582231522
39 - whirlpool 0.66826415062
40 - snefru256 0.866051673889
41 - snefru 0.873198509216
42 - md2 1.85310149193


Hashes Compared

1 - crc32 ab6bce26
2 - crc32b a858f80e
3 - md4 6b5f6832624aa2a62dff0e1e1ca9782c
4 - md5 651174af49d11b8a37d5af8f7ac2ebf2
5 - sha1 3da56487bf3ee10fd89bffb9de70958fcd1eccaf
6 - adler32 d7bcb36d
7 - tiger192,3 3b2f4e9ce737c55694d15a7b7de07a95f7cdc4fef200ee80
8 - tiger128,3 3b2f4e9ce737c55694d15a7b7de07a95
9 - ripemd128 3db40be35a1b4809165d4ec4c4419116
10 - tiger160,3 3b2f4e9ce737c55694d15a7b7de07a95f7cdc4fe
11 - ripemd256 465f4057308a3b278e4a5d848913f6e321724caa822f366b98971f46755769e6
12 - salsa10 cd51bb98aa8be1047b637ee729573c95e2930ea6bc89b015e1ca45b219aef9269c0bf33799eb977e49264d4dbf94a97de5020f7b40bfd9e4199c896ebaa8f041
13 - tiger160,4 a45bcd00ca9cb066cf8162985462e075f8d92fcd
14 - tiger192,4 a45bcd00ca9cb066cf8162985462e075f8d92fcd7ea1bdc8
15 - tiger128,4 a45bcd00ca9cb066cf8162985462e075
16 - haval224,3 f5a41fe0934675b8618312da94dd5dbe9f60d8558c7623cea515ac80
17 - salsa20 3132bfbd6f055ad5e12a689c0159626c564ac392ad1a70d78a9be82e2bda2a35e0aa71d9a5a2873ba8a21ce7e8f6a36724383737eb951526915625904e64c5c1
18 - haval192,3 3aab1fe0204975b8aa8612da96e05dbe6664d855487d23ce
19 - sha256 e83d87d2641712bcb4efd58c8a1dc6b8e367df83c3f144c50ac2da7827cc64fb
20 - haval160,3 ded422e0eb947ab8e1e816daeb0d65be510be655
21 - ripemd320 20545474676f7eba741e76e11e1f1c3f77c138697c7651e4277c942a14d037fcbcac969716753078
22 - ripemd160 17e1639be09e1e9b49ab0b820236721d9d87b3db
23 - sha224 da147a3194d52316c74e490eb5d521423c24906b205b97d89279aaff
24 - haval256,3 daa41fe0844675b85e8312da91dd5dbe9a60d855837623ce9c15ac80996accdb
25 - haval128,3 3ac89f795c151223b30628a62b540a9a
26 - haval256,4 4a335ea8aa07a6824db40e91f3fd8ef9f7db1b9dda25af1ec18f26412917a79a
27 - haval160,4 5f5b63a83988a98227d415910a9891f9698e259d
28 - haval224,4 5d335ea8b407a68256b40e910bfe8ef902dc1b9dec25af1eca8f2641
29 - haval128,4 25e39fd1c525679aea8e9e38ea23b593
30 - haval192,4 9a355ea8cb0aa6820bb50e91d6ff8ef99dde1b9da32aaf1e
31 - haval224,5 2e0924bd900081a2369c6cbd72e421ab9df5081cb955e9696c2bf898
32 - haval160,5 631c29bdbf9281a28f0770bdedc427ab32050d1c
33 - haval192,5 4c0b24bdaf0181a2439f6cbd21eb21ab15f7081cae57e969
34 - haval256,5 260924bd8b0081a2289c6cbd57e421ab9df5081ca755e969642bf89828617b41
35 - haval128,5 1bf3bce59369e50344439838f4391aed
36 - sha384 42c573a2f7d782ec1cea504aeac8ac2fc2333ffb944ff66352381156e473f540c5bc903e8a61ccfaa4d4b834b0774007
37 - sha512 e079e5afee4a96fef7456c5c50271daeb6bf79d5b539ab052fe0173a613d58d267ba202f5d52b4da87355e5687365895fc2cb0b3e57b195053ded6172668de02
38 - gost 14e8788685c65af29e381759550a60340330ad67637578833de02717f032638f
39 - whirlpool 122077c8adb99aef129edcfd330908ca69da138ee1260e25881425b6e94de09d8640f0ed2ad17f9cfee38b62ebaef30d6ed408546e1990c8d35f906cccc5dcf7
40 - snefru256 1909e6a91b71c4df359f9b8f04ff0c118458db425434e93e2ea01ad7f87af6f2
41 - snefru 1909e6a91b71c4df359f9b8f04ff0c118458db425434e93e2ea01ad7f87af6f2
42 - md2 af498550d2f33be614ce6804ffcc8c7d


Hashes Posibilities

1 - whirlpool 1.34078079299E+154
2 - sha512 1.34078079299E+154
3 - salsa20 1.34078079299E+154
4 - salsa10 1.34078079299E+154
5 - sha384 3.94020061964E+115
6 - ripemd320 2.13598703592E+96
7 - gost 1.15792089237E+77
8 - haval256,4 1.15792089237E+77
9 - sha256 1.15792089237E+77
10 - haval256,3 1.15792089237E+77
11 - snefru 1.15792089237E+77
12 - haval256,5 1.15792089237E+77
13 - snefru256 1.15792089237E+77
14 - ripemd256 1.15792089237E+77
15 - sha224 2.69599466672E+67
16 - haval224,3 2.69599466672E+67
17 - haval224,5 2.69599466672E+67
18 - haval224,4 2.69599466672E+67
19 - tiger192,3 6.27710173539E+57
20 - tiger192,4 6.27710173539E+57
21 - haval192,3 6.27710173539E+57
22 - haval192,4 6.27710173539E+57
23 - haval192,5 6.27710173539E+57
24 - haval160,5 1.46150163733E+48
25 - tiger160,4 1.46150163733E+48
26 - ripemd160 1.46150163733E+48
27 - haval160,3 1.46150163733E+48
28 - sha1 1.46150163733E+48
29 - tiger160,3 1.46150163733E+48
30 - haval160,4 1.46150163733E+48
31 - tiger128,4 3.40282366921E+38
32 - haval128,3 3.40282366921E+38
33 - md5 3.40282366921E+38
34 - md4 3.40282366921E+38
35 - haval128,5 3.40282366921E+38
36 - haval128,4 3.40282366921E+38
37 - tiger128,3 3.40282366921E+38
38 - md2 3.40282366921E+38
39 - ripemd128 3.40282366921E+38
40 - adler32 4294967296
41 - crc32b 4294967296
42 - crc32 4294967296


Hashes Average Rank

1 - salsa10
2 - salsa20
3 - ripemd256
4 - tiger192,3
5 - ripemd320
6 - sha256
7 - haval224,3
8 - sha1
9 - haval256,4
10 - tiger192,4
11 - haval256,3
12 - md4
13 - md5
14 - sha224
15 - tiger160,4
16 - haval192,3
17 - sha512
18 - tiger160,3
19 - whirlpool
20 - sha384
21 - crc32
22 - crc32b
23 - tiger128,3
24 - gost
25 - haval256,5
26 - haval224,4
27 - adler32
28 - tiger128,4
29 - haval160,3
30 - ripemd160
31 - haval224,5
32 - ripemd128
33 - snefru
34 - haval192,4
35 - snefru256
36 - haval160,5
37 - haval192,5
38 - haval160,4
39 - haval128,3
40 - haval128,4
41 - haval128,5
42 - md2


Entire page took 23.759114027 seconds
  • 写回答

1条回答 默认 最新

  • douping7975 2011-02-16 19:32
    关注

    AFAIK, you are in the right way. Maybe you want to use memcached instead of filesystem.. That'd be faster.

    Here you'll find all the hash algorithms that PHP handles. Make a benchmark or test them to get more info to find out what's the better solution based on whatever you use as input.

    Then you get the parsed/merged HTML before echoing it, and save it into your memcache.

    Please, ensure to add the date/time of the template file, or reset the cache anytime you modify any template file. If you don't take care of this you'll be serving outdated versions of your pages.

    Good luck!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64