Friday, November 30, 2007

PHP6的新特性和更新

1.支持Unicode
支持Unicode是有其必然,虽然Unicode占用较多的空间,但Unicode带来
的便利性,远超过占用空间的缺点,尤其在国际化的今天,硬件设备越来
越强大,网速也大幅度的提升,这么一点小小的缺点是可以忽略的。另外
一点,PHP也可以在.ini文件中设定是否开启支持Unicode,决定权在你自己,
这是一个不错的点子,关掉Unicode的支持,PHP的性能并不会有大幅度的
提升,主要的影响在于需要引用字符串的函数。

2.Register Globals 将被移除
这是一个重要的决定,说多新进的PHP开发者会觉得Register Globals满
方便的,但是却忽略了Register Globals会带来程序上安全性的隐患,大
多数的主机上此项功能是关闭的,印象中从PHP4.3.x版开始时,此项默认
设置值即是关闭状态,PHP6正式移除Register Globals也代表着如果程序
是由PHP3时代的产物,将完全无法使用,除了改写一途外,别无他法。相
信现在的PHP世界里,仍使用PHP3时代所产生的程序应该是少之又少。

3.Magic Quotes 将消失
Magic Quotes主要是自动转义需要转义的字符,此项功能移除叶符合大多
数PHP开发者的心声。

4.Safe Mode 取消
老实说,这个模式不知道哪里不好,取消就取消吧,反正也用不到

5.'var' 别名为 'public'
在类中的var声明变成public的别名,相信是为了兼容PHP5而作的决定,
PHP6现在也可以称作为OO语言了。

6.通过引用返回将出错
现在透过引用返回编译器将会报错 例如$a =& new b()、function &c(),
OO语言默认就是引用,所以不需要再使用&了。

7.zend.ze1 compatbility mode 将被移去 Zend.ze1相容模式将被移去
PHP5是为兼容旧有PHP4,所以在.ini中可选择是否
开启相容模式,原因在于PHP5使用的是第二代解析引擎,但是相容模式并不是百
分之百能解析PHP4语法,所以旧时代的产物,移除。

8.Freetype 1 and GD 1 support 将不见
这两个是很久的Libs,所以不再支持,GD1早已被现在的GD2取代了。

9.dl() 被移到 SAPI 中
dl()主要是让设计师加载extension Libs,现在被移到 SAPI 中

10.Register Long Array 去除
从PHP5起默认是关闭,再PHP6中正式移除。

11.一些Extension的变更
例如 XMLReader 和 XMLWriter 将不再是以Extension的方式出现,他们将被移入
到PHP的核心之中,并且默认是开启,ereg extension将被放入PECL,代表着它将
被移出PHP核心,这也是为了让路给新的正则表达式extension,
此外,Fileinfo extension 也将被导入PHP的核心之中。

12.APC将被导入核心
这是一个提高PHP性能的功能,现在它将被放入PHP核心中,并且可以选择是否启用APC

13.告别ASP风格的起始标签
原来是为了取悦ASP开发者转向使用PHP,现今已经不再需要这种做法了,

最后,别期望PHP6的性能可以全面超过PHP5,有可能的是PHP6的执行效率会比
PHP5还要来的慢的,但是可以预期的是,PHP开发小组将会努力的完善PHP5,超
越PHP5。
那么,对PHP6有兴趣的朋友现在可以到PHP官方网站上下载,试试这些功能是否真的已经
在PHP6中体现出来了,下载地址http://snaps.php.net/

Wednesday, November 21, 2007

Centos libstdc++.so.5

CentOS libstdc++.so.5 可以这样安装:
sudo yum install compat-libstdc++-33.i386

Tuesday, November 20, 2007

Oracle Startup Script


#!/bin/sh
#
# dbora This scripts starts and shuts down the
# oracle database
#
# chkconfig: 345 99 10
# description: This script calls the dbstart script
# to start Oracle
# and dbshut to stop it
# processname: oracle*
# config: /etc/oratab
#
# Set ORACLE_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORACLE_HOME.
export ORACLE_BASE=/opt/oracle10
export ORACLE_HOME=/opt/oracle10
export ORACLE_SID=DSSDB
ORACLE_HOME=/opt/oracle10
ORA_OWNER=oracle
if [ ! -f $ORACLE_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
su $ORA_OWNER -c $ORACLE_HOME/bin/dbstart &
su $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" &
;;
'stop')
su $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop " &
su $ORA_OWNER -c $ORACLE_HOME/bin/dbshut &
;;
'restart')
su $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop " &
su $ORA_OWNER -c $ORACLE_HOME/bin/dbshut &
sleep 15
su $ORA_OWNER -c $ORACLE_HOME/bin/dbstart &
su $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl start " &
;;
esac

Friday, November 16, 2007

Centos Yum 国内配置文件


#
# /etc/yum.conf
[main]
gpgcheck=1
verbose = 0
socket_timeout = 3
enabled = 1
baseurl=http://mirror.be10.com/centos/4.5/os/$basearch/
hostfilepath = /var/cache/yum/timedhosts.txt
maxhostfileage = 1

Thursday, November 8, 2007

cakephp and me

最近一段时间一直在用cakephp做开发,每天都在看api,虽然有点问题找不到,但是连上IRC却可以很好的解决,有什么不好呢?IRC上面有很多热心的人为你解答问题,不过最重要的还是自己努力和谦虚。所以我想把自己这段时间的学习慢慢写到blog上来,最近也在看zendframework,感觉有些复杂,小型项目没有多大用处,不过想要从小的项目发展到大项目我想一开始就用zendframework也是一个不错的选择。

Monday, November 5, 2007

40 Tips for optimizing your php Code


  1. If a method can be static, declare it static. Speed improvement is by a factor of 4.


  2. echo is faster than print.

  3. Use echo's multiple parameters instead of string concatenation.


  4. Set the maxvalue for your for-loops before and not in the loop.

  5. Unset your variables to free memory, especially large arrays.

  6. Avoid magic like __get, __set, __autoload

  7. require_once() is expensive

  8. Use full paths in includes and requires, less time spent on resolving the OS paths.

  9. If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is codeferred to time()


  10. See if you can use strncasecmp, strpbrk and stripos instead of regex

  11. str_replace is faster than codeg_replace, but strtr is faster than str_replace by a factor of 4


  12. If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.

  13. It's better to use select statements than multi if, else if, statements.

  14. Error supcodession with @ is very slow.

  15. Turn on apache's mod_deflate

  16. Close your database connections when you're done with them

  17. $row[’id’] is 7 times faster than $row[id]

  18. Error messages are expensive

  19. Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.


  20. Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.


  21. Incrementing a global variable is 2 times slow than a local var.

  22. Incrementing an object property (eg. $this->prop++) is 3 times slower than a local variable.

  23. Incrementing an undefined local variable is 9-10 times slower than a code-initialized one.

  24. Just declaring a global variable without using it in a function also slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists.

  25. Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance.

  26. Methods in derived classes run faster than ones defined in the base class.

  27. A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations.


  28. Surrounding your string by ' instead of " will make things intercodet a little faster since php looks for variables inside "..." but not inside '...'. Of course you can only do this when you don't need to have variables in the string.


  29. When echoing strings it's faster to separate them by comma instead of dot. Note: This only works with echo, which is a function that can take several strings as arguments.

  30. A PHP script will be served at least 2-10 times slower than a static HTML page by Apache. Try to use more static HTML pages and fewer scripts.

  31. Your PHP scripts are recompiled every time unless the scripts are cached. Install a PHP caching product to typically increase performance by 25-100% by removing compile times.

  32. Cache as much as possible. Use memcached - memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load. OP code caches are useful so that your script does not have to be compiled on every request

  33. When working with strings and you need to check that the string is either of a certain length you'd understandably would want to use the strlen() function. This function is codetty quick since it's operation does not perform any calculation but merely return the already known length of a string available in the zval structure (internal C struct used to store variables in PHP). However because strlen() is a function it is still somewhat slow because the function call requires several operations such as lowercase & hashtable lookup followed by the execution of said function. In some instance you can improve the speed of your code by using an isset() trick.



    Ex.
    if (strlen($foo) < 5) { echo "Foo is too short"; }
    vs.
    if (!isset($foo{5})) { echo "Foo is too short"; }


    Calling isset() happens to be faster then strlen() because unlike strlen(), isset() is a language construct and not a function meaning that it's execution does not require function lookups and lowercase. This means you have virtually no overhead on top of the actual code that determines the string's length.


  34. When incrementing or decrementing the value of the variable $i++ happens to be a tad slower then ++$i. This is something PHP specific and does not apply to other languages, so don't go modifying your C or Java code thinking it'll suddenly become faster, it won't. ++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While code-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend's PHP optimizer. It is a still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer.

  35. Not everything has to be OOP, often it is too much overhead, each method and object call consumes a lot of memory.

  36. Do not implement every data structure as a class, arrays are useful, too

  37. Don't split methods too much, think, which code you will really re-use

  38. You can always split the code of a method later, when needed

  39. Make use of the countless codedefined functions

  40. If you have very time consuming functions in your code, consider writing them as C extensions


  41. Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview

  42. mod_gzip which is available as an Apache module comcodesses your data on the fly and can reduce the data to transfer up to 80%

  43. Excellent Article about optimizing php by John Lim

bootchart.png

工作用机器的启动时间分析

bootchart.png

Thursday, November 1, 2007

Goodbye Dream Host

Dream Host搬出来了,由于种种原因,也许是暂时的,也许又是一年.但是我很高兴,我们还是继续了. 我们的爱呢?

svn使用bd4作为存储库时找不到Berkeley DB的问题

在 ./configure 时遇到错误
error: Berkeley DB not found

使用这样的配置语法可以解决问题
env LDFLAGS="-L/usr/local/db-4.2.52.NC/lib" \
LD_LIBRARY_PATH="/usr/local/db-4.2.52.NC/lib" \
./configure ...