SoFunction
Updated on 2025-04-08

php What is PEAR?

PHP enthusiasts must like PEAR. Our purpose is to introduce PEAR to PHP program developers. I personally believe that the method of citing program libraries has gradually become a trend. In addition to php and JSP, there are also exclusive libraries for developers to reference.
By introducing PEAR, php program developers can not only greatly reduce the work and time of writing code, but also obtain many powerful dynamic web functions in a very simple way. I will list many examples so that after reading it, you will definitely applaud and become deeply fascinated by PEAR. In addition, the code is easy to maintain and high security is also another two very attractive advantages of PEAR. The PAER library is like a module, which can be easily replaced and updated without affecting other codes at all.
We are introducing the most basic concepts, including the meaning of the proper noun PEAR? Where can I get the PEAR package? How to use PEAR suite, etc.
Starting from Chapter 2, we will first introduce the origin, history and characteristics of PEAR so that everyone can have a basic understanding of PEAR.
Chapter 3 We will introduce the installation and management methods of PEAR library suite. This chapter is very important. Before using PEAR, you must first learn these basic skills. Although it is a bit complicated, it will benefit endlessly after learning it, which will double the efficiency of your PHP program development and increase the functions as you increase.
Chapter 4 is a simple example to introduce how to reference PEAR library to develop PHP programs, allowing us to understand the general usage of PEAR and also establish a basic operation process for the use of the library.
In Chapter 5, we will introduce several examples of library suites that are simple to use and powerful, so that you can quickly create some cool features on dynamic web pages that you could not imagine before, so that your programming skills can be improved immediately. For example:
◆ Let the web page provide weather forecast function and increase the added value of the web page.
◆ Use a very simple method to create cache for web pages on the server to speed up the opening speed of web pages.
◆ Search for a host on a dynamic web page that provides services that provide PORT numbers.
◆ Query a domain name (DNS) on the dynamic web page to find the corresponding IP.
◆ Dynamically generate HTML tables.
◆ Quickly establish a "customer reply" system so that web browsers can send letters to website administrators from the web page.
◆ Let the web page record the behavior of web browsers, that is, do logging.
From Chapter 6 to Chapter 13, we will introduce in detail some very important, commonly used, but more complex library suites. These chapters are all based on the suite as the main axis, that is, one chapter only introduces one suite, and we must introduce the more important functions of these important suites to you in detail.
These packages include: library connection kit, form production kit, identity authentication kit, archive upload kit, paging kit, etc.
Finally, Appendix A will give a detailed introduction to PEAR's official website. When you enter the world of PEAR, you will definitely come to this website to find information frequently. Knowing how to use the official website is very important for those PEAR PHP developers. Appendix B will give a brief introduction to PHP's object-oriented program design.
Those who like and are suitable for PEAR are classified as follows:
◆ For php enthusiasts, you must use PEAR because it is absolutely great.
◆ Professional programmer of PHP. What you need is the security, repeatability, and good work efficiency of the code. PEAR is absolutely a must-have.
◆ PHP program players want to develop more interesting and more powerful applications, but don’t want to be tied up by some of the worries about writing PHP programs. PEAR can definitely meet your requirements.
◆ Write your own PHP program, but don’t like to start from scratch every time and type the code word by word. PEAR can improve your work efficiency.
◆ If you want to learn PHP with strong functionality and high security, you can try to use PEAR after learning the basic syntax of PHP.
◆ You need a tailor-made PHP application. In other words, you don’t like set applications like XOOPS, try PEAR.
◆ You need a PHP application that is easy to maintain, and you don’t want to modify the code in the future, or redesign the entire program due to PHP revisions.
◆ You hope that your PHP program can be object-oriented, which facilitates program replacement and modularization.
◆ You hope that your PHP skills will be improved to the next level. If you want to learn more about PHP, it is a good learning method through the use of PEAR or watching the original code of PEAR.
PEAR is written specifically for people with the above needs.
Using PEAR is like building a house. It allows you to build a large house designed and constructed by yourself with prefabricated parts, but you don’t need to mix cement by yourself, prepare sand, stone and burn tiles by yourself. Make your own aluminum doors and windows, do your own woodworking decoration, etc.
PEAR is like prefabricated and prepared to suit your needs, you just need to use creativity to combine them.
When we use PEAR to write PHP programs, we must have a prerequisite, that is, we must have a certain understanding of the relevant knowledge of PHP.
If you don't know what PHP is, what Apache, Mysql is, or you know that you don't know the basic syntax of PHP, then this article is not suitable for you at the moment. It is recommended that you buy some introductory books for PHP, Apach, and Mysql. After studying it in detail, you can read this article.
Everyone does not have to be a PHP expert, but they must have the ability to understand the basic PHP program code. In any case, first of all, love for PHP is the most basic prerequisite for reading this book.
Chapter 2
PHP has many specifications and syntax, we will not introduce it. Please read books about PHP when you have time. What we are focusing on is that PHP has developed to version 4.0. The Object-Oriented Programming Language function has been added. Although it is still impossible to achieve complete object orientation like Java, it is a great improvement compared to the previous version of PHP3.0, and also provides PHP program developers with stronger and more convenient development capabilities.
Versions of PHP 5.0 or above have been transformed into a thorough object orientation, providing more complete object orientation functions. The PEAR library we introduced is fully supported for PHP 4.3.0 or above. Please rest assured about this.
For the sake of most people and considering the downward compatibility of PHP, the content and examples of this book can be executed in environments such as PHP 4.3.0 or above, because PEAR fully supports PHP 4.3.0 or above, which is smaller than PHP 4.3.0 or above. Most of the PEAR is also supported, and only a small number of them do not.
What is PHP object orientation? The object orientation syntax is rarely seen in traditional PHP programs, but if you understand the programming language of JAVA, you should be able to know what object orientation is. I will give a brief explanation of object orientation in Appendix B.
In addition, what I want to emphasize is that in addition to basic syntax, PHP has more than a thousand built-in functions, spanning hundreds of types, including text functions, digital functions, databases, graphics, etc., with quite powerful functions and are very impressive. But compared with program developers, how to make good use of these functions and write effective and manageable code in conjunction with PHP grammar will be a big challenge.
Today, PEAR, a wisdom crystallization produced by many top PHP experts in the world, allows us to write code easily and efficiently and overcome many writing difficulties. Taking the example of the martial arts world, writing PHP with PEAR is like hundreds of martial arts masters infusing their skills to program developers. Let program developers not start from the most basic practice and horse stance. Borrowing their skills can easily double their skills and efficiency.
After talking for a long time, what is PEAR? I will introduce it to the next unit.
The word PEAR simply means "pear".
A pear. The website address of the official website is
Examples can be seen in the logo of the official PEAR website.
The PEAR started on November 21, 1999. There was a gentleman named Stig. This guy launched a special project and called on many PHP experts to join in. He first established some basic rules for the program for this special project. He hoped that the PHP code written by PHP developers when joining this special project must abide by these rules.
The name of this project is PEAR, which is actually the abbreviation of PHP Extension and Application Repository, which means "PHP continuation and application library". Simply put, PEAR is actually a PHP library.
The basics of the code established by Mr. Bakken are as follows. I will only briefly explain it and will not talk about the details in detail:
◆ If the developer wants to provide a PHP program library, the structure of the program must be objectified.
◆ The program's indentation must follow a certain format
◆ The naming of classes in the program must also follow a certain format.
◆ The code explanation must have a certain format
◆ Archive naming must have a certain format
◆ After the library is written, it must be packaged into a kit, and the package and installation method of the kit also have a certain format.
This project welcomes all PHP developers to jointly develop PHP libraries as long as they are willing to abide by the above-mentioned basic code rules. Mr. Bakken also organized a team as the control body of this project, responsible for reviewing the libraries provided by all developers involved in the project. If the audit passes, the library will be classified and placed in the official website for other developers to download and use. In addition, this group is also responsible for maintaining the maintenance and update of the official website.
Some people may be curious why some people are willing to write a library for free for others to use? This is the spiritual mutual assistance and sharing of the open original code world. Just imagine, if each developer specializes in some of the development libraries for others to use, and also enjoy the libraries released by other developers, can we achieve the purpose of mutual assistance and let each developer share the results of all developers? You don't have to write all the code yourself.
What's even better is that these libraries are free to people around the world, and are not only used by developers participating in library development (this approach is the same as Java or perl's approach to providing libraries).
Therefore, all PHP developers around the world can save a lot of time writing codes. Because developers using the library can return the missing library to the original developer, the original developers will constantly correct these libraries, so the code is relatively safe. In addition, library developers will also evolve with the times and add new functions to the library, so that the users of the library can keep pace with the times.
For details, please refer to the instructions for the purpose of developing PEAR mentioned in PEAR's official website: /manual/en/. I suggest you have time to read it slowly. If you continue reading this article, you will slowly understand the magic of PEAR.
I have an appendix at the end of the article: Introduction to the PEAR official website, you can refer to it first.
If you don't know much about what I mean by "program library", it doesn't matter, the next section will be explained through practical examples.
2-3 Introduction to all kits
▓ Library VS Suite
Before introducing all suites, we must clear the two nouns to avoid confusion among readers. One is "program library" and the other is "kit".
If I were a PHP developer, I developed a "library" that can handle all library inventory and withdraw, and I would like to add this library to PEAR and share it with the whole world for use. After I finish writing the library library, I must compress the library into a "piece" file according to the PEAR regulations and place it on the PEAR official website for everyone to download. Since the archive is compressed in accordance with the PEAR regulations, this kit can be installed or managed using the PEAR suite management instructions, which is quite convenient for PEAR users. Regarding the suite management instructions, I will give a complete explanation in the next chapter. After the above explanation, I believe readers should understand what "program library" and what "kit" is? In fact, simply put, wrapping the library becomes a suite.
▓ Kits and Classifications
PEAR has released more than 300 kits so far, divided into 35 major categories, and is constantly increasing. You can imagine how great a unity force is the combination of top PHP developers in the world. The following picture shows the categories of kits in the official website:
Because PEAR has released too many kits, for the convenience of management, the kits are classified according to the functions of the kit. The same type of kits are related in terms of effects, but the functions provided are not the same. Next, I will give a brief introduction to all categories in the form of a table to let everyone learn more about what functions can PEAR kits provide.
With so many categories, each category will develop different suites according to different functions. Taking the first certification class as an example, if you go to the official website, you will find that there are currently 8 suites in this class.
These 8 suites are all related to identity authentication. If you want a web page to have identity authentication function, for example, you can allow web browsers to register, enter account password, determine identity, give permissions, etc. These kits will be needed.
Let me add one more: some suites have matured, developers will call it stable, but if the library is still in development but can be used, developers will release it, which is usually called an alpha or beta version. The official website will also record the names of the developers and maintainers of the suite. Sometimes a suite is developed by many people.
Information about these kits can be found in the official website of PEAR. I will introduce how to use the official website of PEAR in the attachment "Introduction to the official website of PEAR".
2-4 Simple examples of using PEAR library
In this section, I use l simple examples to illustrate the use of the program library.
Assuming you want to make a web page and want to know the time it takes to execute the web page, you can borrow a library named Benchmark released by PEAR. The purpose of this library is to calculate the execution time of a web page.
First, install the Benchmark library suite (please refer to the next chapter for the installation method). Then we can start writing a web page, for example: we have created a web page called.
Based on the convenience of explanation, I add line numbers to each line program, and you don’t actually need to add line numbers when writing programs.
The codes on lines 1 and 2 first refer to the web page in the Benchmark suite, which contains a library that calculates the execution time of the outline page. include_once can put an external web page on this outline page. I call this action "reference". This example is equivalent to executing two web pages.
Line 3, use the new keyword to create a Benchmark_Timer object and put the object into a variable named $timer. Then use the start( ) method of the fine $timer object to start the clock, and then add my own code. In this example, a simple program.
Then it is timed to end the clock, calculate the time it takes to execute the web page and display it. In line 8, first use the stop( ) method of the $timer object to stop the clock, and use the timeElapsed( ) method of the $timer object to calculate the time difference between the clock from start to stop, and put the calculation result into the $totaltime variable.
Finally, use the echo function to display the time difference on the web page.
From the results, we can clearly see that the web page takes a total of 0.00013613700866699 seconds from the beginning to the completion of execution. In the future, you can use this number to judge the system performance by observing this number, or as a reference for code improvement. How, is the calculation of execution time convenient, fast and magical?
If you need to calculate the execution time of the web page on other web pages, you can just apply the above method to other PHP web pages.
In fact, the usage of other kits is similar to the usage of this kit. The difference is just that the classes, methods and parameters provided by each suite vary.
Although the kit is easy to use, I believe readers still have many doubts? For example:
1. How did the Benchmark library suite come from? What pre-works are required to use it?
2. How do I know how to use the Benchmark suite?
The first question involves how to install the PEAR suite, as well as the management, upgrade, and delete of the suite after installation. I will introduce it in Chapter 3. For the second question, the author will give a detailed explanation in Chapter 4 on how to use the kit and how to obtain information about the kit.
2-5 Why use PEAR
Why use PEAR? Based on my own experience, I summarized the following points:
1. Save time and effort: Many codes are written in the library. Developers only need to reference the PHP file containing the library to have the functions provided by the library, saving time and effort to write by themselves.
2. Security: Since these library suites expose the original code, if users find bugs, they can immediately report to the developer of the suite. The developer usually corrects them immediately to minimize the errors in the library.
3. Easy to maintain: The self-written code is separate from the PEAR library's code. If the PEAR suite releases a new version because of new functions being developed or errors corrected, you only need to update the suite, and you will not touch the self-written code at all.
4. Powerful functions: PEAR kit provides a lot of functions, in addition to common functions such as: database connection, file setting processing, identity authentication, and form processing. In addition, more advanced functions, such as online post office, network management, dynamic production of graphics, RSS, Wiki, or BBCode analysis of phpBB, etc., can be easily achieved.
5. Separate the programming of web pages from layout design: PEAR provides many program libraries with type boards, which can separate programming from layout design, making it easier for program developers and web designers to divide the work and cooperation.
6. It is an excellent learning example for those who learn PHP: the explanation of the library is very detailed, and the writing of the code has certain rules and formats, and is completely materialized, making it easy for developers to understand and learn. Some kits also come with teaching documents and examples. The most important thing is: you don’t have to spend half a cent to get it. We should thank the authors of the kit for their selfless contributions to us.
2-6 Why set up a PEAR community
What is the reason that has prompted PHP developers around the world to unite and jointly develop the treasure house of PEAR? I think there are several reasons:
1. A strong competition from other competitors: This point has been explained in Chapter 1.
2. Materialization of PHP: After adding the material-oriented function from PHP4, PHP5 has been further materialized. In addition to competing with JSP, it is convenient for program modularization, so that the development of the program can be carried out. With the materialized function, the program library can be cut from the code written by the developer.
3. Common needs of developers: If you develop a PHP program every time you want to do it yourself from scratch. Although you can exercise the skills of the program, it is not efficient and not very economical. If some commonly used functions can be handled in the form of a library, it will solve the difficulties of many developers. Based on this need that all developers share the same, these PHP developers can divide the work and cooperate to develop the library together, and help themselves and others.
2-7 PHP's competitors and advantages and disadvantages
PHP was developed in 1994 and after four major rewritings, it has become a widely used and mature product we see today. As of April 2005, PHP has been used on more than 19 million websites around the world, and this number is still growing rapidly.
PHP has the following advantages over their rivals:
High efficiency: It’s not that I, Huang Po, sell melons, haha. .., I have read many web pages with JSP, but the performance is really incomparable to PHP. (Users with Jsp probably won’t read this article).
● Can be linked to many different database systems: other competitors can do it, but there is no PHP fast.
● Easy to learn and use: The writing method of PHP's code is very intuitive and easy to learn.
● Support object orientation: Jsp is a strong point in this regard, but PHP5 has caught up.
● Low cost: no money at all.
● There are many built-in function libraries: I remember that I used Asp before, and there were very few built-in function libraries.
● Open source code: The security will be higher than that of non-open ones.
● PEAR library: This is the most recent powerful weapon used to compete with powerful enemies.
● Compatibility: PHP can be used for all types of Unix operating systems, such as Linux, FreeBSD, commercial Unix or Windows operating systems.
Of course, Jsp also has their unique advantages? For example, Jsp entrains JAVA's powerful functions, which can present some effects that PHP cannot do at present. Therefore, Jsp has attracted many users, but the author is not very satisfied with the current performance of Jsp. On the contrary, he is extremely satisfied with the speed of PHP.
Which program to use is up to you to make a clear choice. However, if you choose to watch the article, I believe we should all be fellow practitioners and PHP enthusiasts.
In short, many PHP experts have jointly built a powerful support network. If you are a PHP program developer and you don’t appreciate the kindness of these experts, wouldn’t that be a pity?