六月三十号,PHP.net发布了5.3.0版本的Release版本。
一直没有时间来关注,今天特别去看了一下,增加了很多有意义的新特性:比如众望所归的命名空间支持。
原本以为这会在PHP6里才会实现,没想到5.3.0就增加了。在PHP6之前,5.3.0也确实算得上一个比较值得关注的版本了。
简单列举一下比较值得关注的特性,关于全部的更新日志可以参考ChangeLog(http://www.php.net/ChangeLog-5.php#5.3.0)
另外PHP团队提供了一个专题来指导如何将5.2.x的项目迁移到5.3.0,参见http://www.php.net/migration53
由于没有linux的环境,因此只能在win下分析一下,欢迎拍砖。
1、更改mysql的扩展为mysqlnd
mysqlnd是MySql专为PHP6设计的驱动,采用PHP开源协议,避免了版权争议,并且置于php内部了。仔细对比就会发现5.3.0的windows版本中少了libmysql.dll这个文件,正是因为使用了mysqlnd驱动,因此libmysql.dll这个外部驱动也没必要存在了。使用mysqlnd驱动并不会改变使用mysql或者是mysqli的使用方式,并且会提升一些性能。
2、去掉了ISAPI扩展
想要在IIS中使用PHP 5.3.0,没办法再像以前那样在IIS添加.php扩展名到php5isapi.dll上了。所以在IIS上使用PHP 5.3.0的方式只有CGI和Fast-CGI两个选择了。现在还有谁会用老古董的CGI么,所以只能用Fast-CGI了。
由于手头只有vista环境,下面将在介绍IIS7下使用PHP 5.3.0
1)打开IIS的CGI功能
依次打开 控制面板-程序-打开或关闭Windows功能,打开 Internet信息服务-万维网服务-应用程序开发功能-CGI(选中此选择框后将同时打开CGI和FastCgi功能)
2)添加PHP 5.3.0支持
打开IIS管理器,选择服务器(应用到所有网站)或者某个网站(应用到单个网站)。选择处理程序映射选项,将会列出所有程序映射。在右侧选择添加模块映射。然后路径填写为*.php(如果要处理其他扩展名,依次添加即可),模块选择FastCgiModule,可执行文件选择PHP 5.3.0下的php-cgi.exe即可。名称自定,如需要更多设置,点击请求限制。
3)设置php.ini
php.ini放置于PHP 5.3.0文件夹下即可,设置方式和以前没有什么不同。不过要设置date.timezone = Asia/Shanghai,不然运行时会报错。ok,然后就可以看phpinfo()了,需要什么扩展,自行打开就行了。
3、命名空间支持
在PHP 5.3.0中终于添加了命名空间支持。PHP程序员一直的都是很傲气的,因为他们有众多强大无比的开源项目(Drupal、Wordpress等等),可是提到命名空间却不得不无奈。现在PHP团队终于将本来构思在PHP6中的命名空间提早到了PHP 5.3.0。在PHP中使用命名空间同样使用namespace关键字。
4、静态延迟绑定
在PHP 5.3.0增加了静态延迟绑定支持。增加了使用static关键字和get_called_class()等几个函数来实现访问继承树中的特定成员。
5、闭包
PHP 5.3.0中增加了对闭包的支持,可以方便的使用匿名函数或者Lambda表达式。可以将函数放在一个变量中。这个对笔者来讲才是最期待的功能。
6、垃圾回收机制
在PHP 5.3.0中增加了可选的垃圾回收机制。作为可选的功能,看来PHP团队对这个功能也不怎么上眼。毕竟对于Web来说,页面执行完毕后,所有的资源全部释放掉了,也没必要特意的处理资源回收。聊胜于无吧。
7、优化了大量的函数,修复了大量的bug
根据PHP.NET的说法,修复了超过140个Bug。增加了若个扩展。另外优化了很多已知函数的性能,比如md5()速度就提升了10%以上。关于全部的更新,可以参考ChangeLog(http://www.php.net/ChangeLog-5.php#5.3.0)
5.3.0这个版本提供了大量的新功能,并且对整体性能进行了大幅度的优化,整体性能的提升到达10%左右。所以,可能的话,还是赶快把项目升级到5.3.0吧。
参考:
ChangeLog
Migrating from PHP 5.2.x to PHP 5.3.x
php 5.3带来了什么

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
