author | BEN JAMES
translator | Arvin, editor in charge | Produced by Xiyan
| CSDN (ID: CSDNnews)
In June 1995, Rasmus Lerdorf made the following announcement in the Usenet group . The announcement is still there and can be read at any time.
announcement:
officially released version 1.0 of the personal homepage tool (PHP tool).
These tools are a set of small and compact cgi binary files written in C.
Today, 25 years have passed, and PHP is almost everywhere. I bet that for most readers of this article, their first attempts at web programming involved PHP.
However, no matter how rich PHP has a history and extensive user base, there is no reason to use this language in a rapidly developing field. Although PHP will inevitably appear in existing applications for several years, does it have a future in new sites?
Before looking to the future, we must first study how PHP has developed in the past.
originator
Rasmus Lerdorf originally created PHP to track users who viewed his online resume. When the source code was released, the code base was extensively rewritten, and PHP became popular. According to reports, by 1998, 1% of domain names had PHP installed. At that time PHP was written entirely in markup, and the syntax was significantly different from modern versions.
Zeev Suraski and Andi Gutmans tried to build a business with PHP, but found that it was lacking in functionality. They cooperated with Rasmus, PHP was rewritten again and released PHP 3.0 version. Things made some progress at the time, and it is estimated that 10% of domains have PHP 3 installed. This is also the turning point in the meaning of PHP from "personal homepage" to the popular recursive acronym "PHP: Hypertext Preprocessor". This version and period is usually regarded as the period when PHP consolidates its position. During the transition period of PHP 3 and 4, phpMyAdmin was created. Zeev and Andi combined their names to create the PHP service company Zend, and the ancient elephant logo was born. The rest of
is classic history: not long after PHP 4 was released, Drupal was born. In 2003, WordPress appeared. In 2004, a Harvard student named Mark (the founder of FB) became famous.
FACEBOOK and PHP
Facebook are well-known PHP websites. However, when tens of thousands of users become millions, and millions of users expand to billions of users, there is growing trouble.
In particular, PHP was (and still is) a scripting language. Good for developer productivity, but not for resource efficiency. Therefore, in 2008, Facebook started working on HipHop for PHP (a compiler). Very simple, it parses PHP, compiles it to C++, and then compiles the generated C++ to x64. Given that PHP is weakly typed and dynamic, this is not a great feat. But the result speaks for itself: CPU load is reduced by 50%.
I'm sure, I can imagine how scary it would be to use this program if you were a Facebook developer. Make changes to the PHP code, run the interpreter, then run the compiler, and then run the executable file, and return to repair after finding the problem. That was a long iterative cycle, which is why Facebook also developed HPHPi, an interpreter that can do the same work as a parser and compiler (HPHPc), but only for development. As you can imagine, keeping these two projects in sync is a headache, so in 2011, they developed HHVM (HipHop Virtual Machine).
HHVM is a PHP runtime. It uses JIT (Just-in-time compilation) to provide the best of both worlds. It's veryCool, if you are interested, you can read more in Facebook's own blog post. The next major development of
was in 2014, when a language Hack specifically built for HHVM appeared. It is both a superset and a subset of PHP, adding optional type annotations and additional features such as asynchronous architecture. It also helps HHVM's JIT to be more efficient because it can optimize HHVM's JIT with confidence by using specified type hints. Soon, the new code on Facebook began to be written in Hack, and the existing code was converted to Hack in the future. Both Hack and HHVM are open source and are now actively maintained.
Facebook found that the fact that PHP in its native form cannot be scaled up on a large scale does it mean that it is a poorly designed language? No, I don't think so. I don't think the options that existed at the time were created for the scale or detail that Facebook required. However, this does not stop people from building Facebook with PHP.
PHP haters
in the vast software community, with the development of PHP, it inevitably attracted more and more cynics attacks. However, objectively speaking, PHP is more annoying than most other languages. According to the recent 2020 Stack Overflow Developer Survey, PHP ranks sixth among the most terrifying languages. Why?
I don't want to discuss the technical details here. If you are interested, you can read "PHP: The Incarnation of Bad Design". This article is simply regarded as a bible by PHP haters. This blog was written in 2012, and some of the issues it mentioned have since been resolved, but many issues have not been resolved. (For example: Why is there still no local asynchronous support in 2020?)
I think PHP has a bigger problem with language philosophy. This is a tool that is implemented in a complex way and is used in a fairly narrow field. Ideally, if the application must be complex, then developers should see the complexity in the user generation, not the language itself. You don't need to use a complex tool to create complex projects. When I say PHP is complicated, I am not saying that it is difficult for beginners to use (in fact, quite the opposite), I am saying that it has inconsistent naming conventions and many very specific functions, both of which are easy Errors are generated, and these errors will not be exposed until runtime. But are these just attributes of the PHP era? Although this may be a factor, it is certainly not the reason why everyone hates it. After all, Python was created in 1989, 6 years earlier than PHP. In a Stack Overflow survey, it ranks third among the most loved languages and is one of the fastest growing languages today.
Stack Overflow 2020 survey: the most terrifying language
When it comes to security, there is some debate about the number of vulnerabilities on the PHP site that are above average, whether it is the language's error or the site developer's error.
On the one hand, a programming language designed to attract a wide range of people, including non-programmers, regardless of the advantages of the language itself, these people use code written in tutorials decades ago to create websites. This programming language There will always be problems. On the other hand, PHP tries to fix basic security problems in puzzling ways, such as first using escape_string() to fix SQL injection, then adding real_escape_string() to fix the vulnerability, and then adding addslashes(), mysql_escape_string(), pg_escape_string() and many more. Add this to its complex error/exception handling (yes, errors and exceptions are different), it is easy to make mistakes if you are not familiar with the nuances of the language. The number of sites running outdated, unsupported versions of PHP will continue to grow at an alarming rate, so in the next few years, PHP sites will remain a low-hanging target for hackers.
Despite this, I don’t think the language has as serious problems as people say. Although people have reasonable grounds for complaining about PHP, it seems to me that most of the stigma is jealous because of its popularity, not personal reasons.
in the future
I know that using the post.php page in the address bar to enter comments on this language is ironic. But this has nothing to do with the existing website. I don’t think even the most enthusiastic users would recommend us to rewrite all websites created with PHP. The question is, in 2020, if I want to create a new website, should I consider using PHP?
There is no doubt that the current web development trend is setting a direction for single-page applications-in such applications, your browser will never reload, but the navigation is through Javascript using API calls (for example: This is achieved by re-rendering the page with the data obtained by browsing GitHub or Google Drive. Such calls are as fast as lightning. The ecosystem of Javascript libraries, frameworks, and tools for building reactive and high-performance applications in the browser continues to grow, with React and Vue being the most popular.
In the final analysis, PHP is used for server-side rendering. This is good for most websites and the best choice for most websites. But if you want to build a new product in 2020, you must accept the restrictions that this will bring. Although PHP-style server-side rendering is not dead yet (have you forgotten SEO?), modern websites are likely to be isomorphic, that is to say, the same Javascript can be rendered on the server and the client, using such as Frameworks such as Next.js (for React) or Nuxt.js (for Vue) can remove PHP from the server.
But we cannot ignore the fact that PHP is also evolving. Laravel bills itself as the "PHP framework for web craftsmen", which provides an MVC architecture for safely and quickly creating PHP applications. It is highly valued by the society, and its development is active and rapid. In addition, PHP 8 was also launched in August this year, bringing a lot of new features (many of which are similar to those introduced in the Facebook chapter), such as JIT, Union types, and improved bugs.
Finally, I wish PHP a happy 25th birthday. Although PHP is weird, it will remain weird for a long time in the future. You have empowered many people and played a key role in the rise of the web. However, if people look for the future elsewhere, don't be too frustrated, after all, it is now 2020.
This article is a CSDN translation article, please indicate the source for reprinting.
https://hackaday.com/2020/06/29/does-php-have-a-future-or-are-twenty-five-years-enough/