PHP 七問世,2億網(wǎng)站效能翻倍有望
Jun 13, 2016 pm 12:27 PM
PHP 7問世,2億網(wǎng)站效能翻倍有望
經(jīng)過10年的漫長(zhǎng)等待,PHP 7終於正式問世了。這個(gè)影響全球8成網(wǎng)站的開發(fā)語(yǔ)言,一舉從5.0版,跳過了功敗垂成的6.0版,一舉進(jìn)入了7.0時(shí)代。
20年前初夏,1995年6月8日,一位愛解決問題的C語(yǔ)言軟體工程師,苦於不知如何用C來(lái)做一個(gè)自己的個(gè)人首頁(yè),因?yàn)闆]人提供C語(yǔ)言版的網(wǎng)頁(yè)開發(fā)環(huán)境。他索性自己來(lái)寫一個(gè),並命名為Personal Home Page Tools,簡(jiǎn)稱PHP Tool。這就是日後用來(lái)開發(fā)出Facebook、Yahoo等全球2億多個(gè)網(wǎng)站的PHP語(yǔ)言最初的版本。而這位C語(yǔ)言開發(fā)者Rasmus Lerdorf,也就成了PHP之父。PHP隨著網(wǎng)際網(wǎng)路從1996年開始起飛,也迅速成為開發(fā)人員打造網(wǎng)站的首選技術(shù)。
不過,在快速進(jìn)化的IT世界中,越早出現(xiàn)的技術(shù),往往也背負(fù)了越重的轉(zhuǎn)型包袱。PHP語(yǔ)言一路跟著作業(yè)系統(tǒng),從32位元架構(gòu)開始跨入64位元,在2004年推出的PHP 5更是一個(gè)體質(zhì)大改造的版本,順利地跨入了物件導(dǎo)向架構(gòu)的世界,穩(wěn)坐網(wǎng)站開發(fā)技術(shù)龍頭。即使微軟打著容易上手為號(hào)召,以ASP網(wǎng)站開發(fā)技術(shù)搶攻市場(chǎng),PHP仍是許多網(wǎng)站開發(fā)者心目中的首選。2008年時(shí),光在臺(tái)灣,每4個(gè)網(wǎng)站,至少有1個(gè)是採(cǎi)用PHP開發(fā)。
不過,2005年時(shí), PHP在Unicode的支援過程上,重重摔了一跤。Unicode支援原本要成為PHP 6的主打特色,但在開發(fā)社群中對(duì)多國(guó)語(yǔ)言支援的爭(zhēng)論,和PHP效能議題的質(zhì)疑,衍生出了漫長(zhǎng)的拉扯論戰(zhàn),也延宕了PHP 6的發(fā)展,甚至PHP 5.3的小改版都搶先在2009年支援了PHP 6的大部分功能(除了Unicode支援外),隔年春天,PHP 6計(jì)畫正式宣告失敗而終止,也讓PHP技術(shù)的發(fā)展,蒙上了一層陰霾。PHP 5持續(xù)改版推陳出新,但總是處?kù)兑环N小改小修的優(yōu)化,而鮮有從根本上革新的大進(jìn)步。儘管語(yǔ)言進(jìn)展緩慢,但PHP的影響力卻是持續(xù)不墜,甚至越來(lái)越大,2013年初,Netcraft網(wǎng)站統(tǒng)計(jì),全球超過2.4億個(gè)網(wǎng)站後端開發(fā)語(yǔ)言使用的就是PHP。
Rasmus Lerdorf今年5月來(lái)臺(tái)演講時(shí)告訴我,F(xiàn)acebook為了自家網(wǎng)站速度而重新改寫了PHP編譯引擎的JIT作法,引起了PHP開發(fā)者對(duì)於PHP語(yǔ)言效能的再思考。
2014年,開始有一群PHP開發(fā)者(包括了來(lái)自中國(guó)的惠新宸)展開PHP語(yǔ)言的重構(gòu),也就是PHP NG專案(PHP New Generation),為了提高效能,他們不惜重新檢視甚至改寫PHP語(yǔ)言原始碼,一試結(jié)果發(fā)現(xiàn),PHP程式的效能大幅提升了30%。
舊版PHP語(yǔ)言的發(fā)展目標(biāo)是希望盡可能地提供更多功能,來(lái)滿足任何網(wǎng)站開發(fā)的需求,但新的PHP 7,則是希望兼顧效能和功能。Rasmus Lerdorf這樣說(shuō)。
但要對(duì)一個(gè)已經(jīng)發(fā)展了10年,歷經(jīng)了全球開源開發(fā)人員精心雕琢之後的開發(fā)語(yǔ)言,還想要找出很大效能突破的關(guān)鍵,不是一件容易的事。
也因此,PHP 5重構(gòu)專案PHP NG的巨大成效,也獲得PHP開發(fā)社群支持,成了PHP 7的基礎(chǔ),開發(fā)社群轉(zhuǎn)而細(xì)細(xì)地推敲每一行PHP程式碼,想辦法從各種地方找出效能優(yōu)化的關(guān)鍵。
例如PHP核心開發(fā)團(tuán)隊(duì)花了很多心力來(lái)縮減PHP程式執(zhí)行時(shí)所需搬動(dòng)的記憶體位元數(shù),像是將PHP儲(chǔ)存變數(shù)的資料架構(gòu)zval從24位元縮減至16位元?;蚴侵匦聶z視CPU層級(jí)的程式碼運(yùn)作過程,來(lái)確保PHP 7程式碼更能符合新一代的處理器架構(gòu)。
每一次修改的優(yōu)化可能只改善不到0.5%的效能,但經(jīng)過了數(shù)百次如此這樣斟酌推敲的成果,就讓PHP 7的效能比舊版提高了一倍。
儘管從PHP 5升級(jí)到7也不是一件容易的事,但對(duì)全球2億個(gè)用PHP開發(fā)的網(wǎng)站而言,PHP 7無(wú)疑是一個(gè)解決既有網(wǎng)站效能瓶頸的新救星。

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

The method to get the current session ID in PHP is to use the session_id() function, but you must call session_start() to successfully obtain it. 1. Call session_start() to start the session; 2. Use session_id() to read the session ID and output a string similar to abc123def456ghi789; 3. If the return is empty, check whether session_start() is missing, whether the user accesses for the first time, or whether the session is destroyed; 4. The session ID can be used for logging, security verification and cross-request communication, but security needs to be paid attention to. Make sure that the session is correctly enabled and the ID can be obtained successfully.

To extract substrings from PHP strings, you can use the substr() function, which is syntax substr(string$string,int$start,?int$length=null), and if the length is not specified, it will be intercepted to the end; when processing multi-byte characters such as Chinese, you should use the mb_substr() function to avoid garbled code; if you need to intercept the string according to a specific separator, you can use exploit() or combine strpos() and substr() to implement it, such as extracting file name extensions or domain names.

UnittestinginPHPinvolvesverifyingindividualcodeunitslikefunctionsormethodstocatchbugsearlyandensurereliablerefactoring.1)SetupPHPUnitviaComposer,createatestdirectory,andconfigureautoloadandphpunit.xml.2)Writetestcasesfollowingthearrange-act-assertpat

In PHP, the most common method is to split the string into an array using the exploit() function. This function divides the string into multiple parts through the specified delimiter and returns an array. The syntax is exploit(separator, string, limit), where separator is the separator, string is the original string, and limit is an optional parameter to control the maximum number of segments. For example $str="apple,banana,orange";$arr=explode(",",$str); The result is ["apple","bana

JavaScript data types are divided into primitive types and reference types. Primitive types include string, number, boolean, null, undefined, and symbol. The values are immutable and copies are copied when assigning values, so they do not affect each other; reference types such as objects, arrays and functions store memory addresses, and variables pointing to the same object will affect each other. Typeof and instanceof can be used to determine types, but pay attention to the historical issues of typeofnull. Understanding these two types of differences can help write more stable and reliable code.

std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

In PHP, to pass a session variable to another page, the key is to start the session correctly and use the same $_SESSION key name. 1. Before using session variables for each page, it must be called session_start() and placed in the front of the script; 2. Set session variables such as $_SESSION['username']='JohnDoe' on the first page; 3. After calling session_start() on another page, access the variables through the same key name; 4. Make sure that session_start() is called on each page, avoid outputting content in advance, and check that the session storage path on the server is writable; 5. Use ses

ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach
