search
HomeBackend DevelopmentPHP TutorialPHP版本如何选择?应该使用哪个版本?_php技巧

超过75%的网站使用了PHP作为开发语言,wordpress,phpmyadmin和其他一些开源项目的盛行,带来了一大批的长尾用户。然而,他们一般安装之后却很少升级。下图是目前PHP的使用统计。

惊人的是,此图的左半部分表示已经不被支持的PHP版本。PHP 5.2早在2011年1月已经不再维护。这并不意味着你就不能使用它,但是这意味着某些安全更新,你就无法跟进了。一些发行版将尝试修复一些BUG,但你的PHP版本似乎有点乏善可陈,因为,你正在使用的是2006年的过时技术。

该从哪里开始

已经没有人选择PHP 5.2版本了,但这些事情已经发生了,但我不是说我写这篇博客来吐槽什么,更不是说给你一些升级的指南。通常他们使用的都是一些2006开始的主机空间,他们有一个“长期支持”的版本,来避免使用更新的版本,或者他们目前还没有升级的打算。又或者,理由真的很多。然而,好东西在新版的PHP等着您。

PHP 5.3 加入了很多有用的OOP特性!例如:匿名函数,SPL扩展不仅仅是迭代器,神话般的DateTime扩展都已经集成在PHP 5.3里面。还加入极其重要的E_DEPRECATED的错误报告标志。它会提醒您现在用的那些特性,将在下一版本无法使用。如果您已经在使用PHP 5.3,那么您往后的升级道路将会更加顺畅。如果您有线上程序运行在低版本,我不建议您升级。

PHP 5.4则进行了一系列的优化,它具有更快的执行效率和更少的内存占用。以下是基准测试的结果。

不管你使用使用到traits特性,PHP 5.4提高了程序性能,并降低了硬件成本。所以,我建议您使用开源软件的时候要保持升级。

PHP 5.5 还在测试当中,不适用于生产环境。自PHP 5.3之后,升级的风险和改动都会大大降低。

下面是麦子同学整理的文章

大家在选择PHP版本时一定很困惑,有这么多版本究竟选那个呢?

问题:

我们现在新买了个服务器,用的是windows server 2008 r2。配置php 5.4的环境。

但我们之前开发的用2003,php是用5.2版本的,移植到新服务器,程序运行会有影响吗?或者我还需要注意那些问题?

API版本

PHP采用大版本向下兼容的升级方式,也就是说5.5兼容5.1-5.4,话虽如此,实际上兼容性并不乐观,大家也不要指望PHP官方会给出什么好的解决办法。现在2013年9月,版本有5.2.17 5.3.27 5.4.17 5.5.3

5.2.17

这一版本可以说是支持最广泛的版本了,现在还有绝大部分开源软件使用该版本,例如Drupal7.23,Joomla2.5,国内绝大多数软件:dedecms5.7,discuzX3等等最新版还在支持5.2,如果没特别要求,安装这一版本是最省心省力的,但长远来看可能终要被抛弃。现在许许多多的主机商为了省人力成本也懒得去升级PHP版本,反正基本上都支持。(这里插一句,现在国内软件为了兼容更多的安装环境,可谓用心良苦,甚至PHP5.1也能支持( discuzX3 不支持),最难得的是性能竟然也没落后多少,能做到如些极致真心不容易!)Drupal6建议使用该版本。

5.3.28(推荐)

这个版本虽然名称上是5开头,但很多人认为是PHP6.0版本的开始,性能有所提升,而且因为许多API都发生了变化,对5.2的兼容不太好,虽然有一部分开源软件声称能兼容5.2-5.3,但问题好像也不少,许多索性就放弃5.2了,例如Joomla3只支持5.3以上。而对于Drupal7强烈建议使用该版本,支持相当好。而对于Drupal8也可以使用该版本,支持也相当不错。该版本使用范围非常广,在兼顾性能和兼容性之间做出一个不错的平衡点。

5.4(轻轻推荐)

5.4基本上已经接近完整体了,现时比较完善,稳定性和性能也不错,未来升级的重点版本,Drupal7.X对其支持尚可,但第三方模块还不太完美。如果懒得以后升级,可以一步到位安装该版本。

5.5

从5.3开始,以后版本基本上都是主打性能上的提升,函数什么的都能向后兼容。5.5开始好像有了64位版本,性能更加强劲,我没试过,不敢发表言论。

总结

如果开源软件说建议安装PHP5.3,那你就老老实实用5.3,别用5.5什么的,你可能认为反正都能兼容,性能可能更好,为什么不用新的呢?话是这么说,但你知道开源软件在开发的时候一般都是在特定的环境开发,就算兼容再好也会有想不到的意外(再强大的队伍也不可能对所有函数API进行兼容测试,那是相当可怕的工作量!),它只会在特定的环境下进行测试和优化,而且就算知道兼容有问题,团队也不会去为了兼容更高版本去修改,不是他们死板,而是为了安全和稳定来考虑的。在开源氛围下,我们应该有个意识就是“够用就是最好”,而不是“最新是最好”。举个列子,Joomla3.1在5.4-5.5都运行不良,甚至安装不能成功。但Drupal却在5.5.3下也运行正常(本机),我想是个别案例吧?但好像运行中出现过意料之外的错误,不知道是不是版本的问题,希望不是。


None-thread-safe or thread-safe

Apache 一般选 none-thread-safe,IIS选后者(FAST-CGI),我就不解释了,信哥就没错。

TS指Thread Safety,即线程安全,一般在IIS以ISAPI方式加载的时候选择这个版本。

NTS即None-Thread Safe,一般以fast cgi方式运行的时候选择这个版本,具有更好的性能。

从2000年10月20日发布的第一个Windows版的PHP3.0.17开始的都是线程安全的版本,这是由于与Linux/Unix系统是采用多进程的工作方式不同的是Windows系统是采用多线程的工作方式。如果在IIS下以CGI方式运行PHP会非常慢,这是由于CGI模式是建立在多进程的基础之上的,而非多线程。一般我们会把PHP配置成以ISAPI的方式来运行,ISAPI是多线程的方式,这样就快多了。但存在一个问题,很多常用的PHP扩展是以Linux/Unix的多进程思想来开发的,这些扩展在ISAPI的方式运行时就会出错搞垮IIS。因此在IIS下CGI模式才是 PHP 运行的最安全方式,但CGI模式对于每个HTTP请求都需要重新加载和卸载整个PHP环境,其消耗是巨大的。

为了兼顾IIS下PHP的效率和安全,微软给出了FastCGI的解决方案。FastCGI可以让PHP的进程重复利用而不是每一个新的请求就重开一个进程。同时FastCGI也可以允许几个进程同时执行。这样既解决了CGI进程模式消耗太大的问题,又利用上了CGI进程模式不存在线程安全问题的优势。

因此,如果是使用ISAPI的方式来运行PHP就必须用Thread Safe(线程安全)的版本;而用FastCGI模式运行PHP的话就没有必要用线程安全检查了,用None Thread Safe(NTS,非线程安全)的版本能够更好的提高效率。

64位和32位

你的系统是64位就选64位,是32位就选32位,不解释,信哥。 

未来

说实话,未来是属于那些使用PHP5.4及以上的人。保持升级,定期跟踪语言的新特性和进展是我们日常工作的一部分。如果您已经落后了,那么我强烈建议您开始做升级计划,升级到一个比较新的版本。努力是值得的,毕竟程序是长年累月运行的。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Describe different HTTP caching headers (e.g., Cache-Control, ETag, Last-Modified).Describe different HTTP caching headers (e.g., Cache-Control, ETag, Last-Modified).Apr 17, 2025 am 12:22 AM

Key players in HTTP cache headers include Cache-Control, ETag, and Last-Modified. 1.Cache-Control is used to control caching policies. Example: Cache-Control:max-age=3600,public. 2. ETag verifies resource changes through unique identifiers, example: ETag: "686897696a7c876b7e". 3.Last-Modified indicates the resource's last modification time, example: Last-Modified:Wed,21Oct201507:28:00GMT.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1?Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1?Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP: An Introduction to the Server-Side Scripting LanguagePHP: An Introduction to the Server-Side Scripting LanguageApr 16, 2025 am 12:18 AM

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP and the Web: Exploring its Long-Term ImpactPHP and the Web: Exploring its Long-Term ImpactApr 16, 2025 am 12:17 AM

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

Why Use PHP? Advantages and Benefits ExplainedWhy Use PHP? Advantages and Benefits ExplainedApr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools