php What is pear? _php Foundation

Source: Internet
Author: User
Tags benchmark file upload pear php books what php
PHP enthusiasts will like pear, our goal is to introduce pear to PHP programmer developers, I personally think that referencing the library program development has gradually become a trend, in addition to PHP, JSP, like Perl, C + + also has a proprietary library for its developers to reference.
With the introduction of pear,php program developers, in addition to significantly reducing the writing code of work and time, can also be a very simple way to get a lot of powerful Dynamic Web page features, I will enumerate many examples, so that everyone can see, will clap applause, and deeply fascinated pear. In addition, the code is easy to maintain, high security is the other 2 attractive advantages of pear, the Paer library as a module, can easily switch and update, does not affect the other code.
We are starting from the most basic concept, including the meaning of the proper noun of pear. Where do you get the Pear kit (package)? How do I use pear kits and so on?
From the 2nd chapter, we first introduce Pear's origin, history and characteristics, so that we have a basic understanding of pear.
The 3rd chapter we will introduce Pear Library suite installation and Management methods, this chapter is very important, in the use of pear, you must first learn these basic Kung fu, although a bit complicated, but learned after the infinite, so that your PHP program development efficiency doubled, function with the incremental.
The 4th chapter is a simple example of how to refer to the Pear Library to develop PHP programs that let us understand the general usage of pear and establish a basic operational process for the use of the library.
In the fifth chapter we'll show you a few examples of simple and powerful library suites that allow you to quickly build on dynamic Web pages Some of the most cool things you've ever imagined, and get your programming skills up to speed. For example:
Let the Web page provide the function of weather forecast, increase the added value of the webpage.
In a very simple way to create a Web page on the server cache, speed up the opening speed of the Web page.
Searching for a host on a Dynamic Web page provides services for those port numbers.
Query a Web domain name (DNS) on a Dynamic Web page to find the corresponding IP.
dynamically generates HTML tables.
Quickly create a "customer return" system that allows web surfers to send letters to webmasters from the Web.
So that the Web page can record the behavior of Web surfers, that is, log.
The 6th chapter to the 13th chapter, we will be very detailed to introduce some very important, very common, but the more complex use of the library suite, these chapters are based on the main axis of the package, that is to say, a chapter only introduces a suite to ensure that these important suites of the more important features, detailed introduction to everyone.
These kits (packages) include: Database cable kits, form making kits, identity authentication kits, file upload kits, paging kits, and more.
Finally, a will make a detailed introduction to Pear's official website, when you enter the world of pear, you will often come to this site to find information. Knowing how to use the official web site is important for the PHP developers of Pear. B will be a simple introduction to PHP's object-oriented program design.
Like and fit to use pear are categorized as follows:
PHP enthusiasts, that must use pear, because it is absolutely wonderful.
A professional programmer for PHP. You need code security, repeatability, and good productivity, and pear is absolutely essential.
The PHP programmer, who wants to develop more interesting, more powerful apps, does not want to be tied up with some of the trouble of writing PHP programs, and pear can definitely meet your needs.
Write your own PHP program, but do not like every time to start from scratch, a word to beat the code, pear can improve your productivity.
You want to learn about PHP, which is powerful and secure, and when you learn the basic syntax of PHP, you can try to use pear.
You need to tailor the PHP application, in other words, you do not like xoops such as a suite of applications, to try Pear Bar.
You need a PHP application that is easy to maintain, and you don't want to change your code in the future, or redesign the entire program because of the revision of PHP.
You want your PHP program to be object-oriented, facilitating program switching and modularity.
You want your PHP skills to be a higher level, you want to learn more about PHP, through the use of pear or watch Pear's original code, is a good way to learn.
Pear is written specifically for those who have these needs.
Using pear is like building a house. It allows you to use prefabricated pieces of the way to build a building of their own design and construction of the big house, but do not need to stir their own cement, they prepare sand, stone, their own roast tile. Do their own aluminum doors and windows, do their own woodworking decoration and so on ....
Pear is like a prefabricated piece that has been customized and ready for your needs, and you just need to use the idea to combine them.
When we use pear to write PHP programs, we must have a prerequisite, that is, the knowledge of PHP must be a certain understanding.
If you do not know what PHP is, what is Apache, Mysql, or you know that you do not have the basic syntax of PHP, then this article is not for you at this time. I suggest you go to buy some php, Apach, MySQL primer books, after detailed study, only to see this article.
Everyone is not necessarily a master PHP, but must have the ability to read basic PHP code. In any case, the first love of PHP is to read the book the most basic conditions.
Chapter II
PHP has a lot of specifications and syntax, we do not introduce, please have time to read about PHP books, we focus on the development of PHP to the 4.0 version after. Added the feature of object-oriented (object-oriented programming Language), although it's not as completely object-oriented as Java. But it has been a great improvement over previous versions of PHP3.0, and it has also provided a greater and more convenient development capability for PHP's program developers.
PHP version 5.0 and above, has been transformed into a complete object-oriented, providing more complete object-oriented features. The Pear Library We are introducing is full support for PHP version 4.3.0. Please be assured of this.
For the most part, and considering PHP's downward compatibility, the contents and examples of this book can be implemented in the context of PHP 4.3.0, because pear fully supports PHP 4.3.0 or more than the PHP 4.3.0 version of the environment, pear is mostly supported, Only a small part is not supported.
What is the object orientation of PHP? Object-oriented syntax is less visible in traditional PHP programs, but if you understand the Java programming language, you should be able to know what the object orientation is, and I'll have a simple description of the object-oriented in the attached B.
In addition, I would like to emphasize that: PHP In addition to the basic syntax, the built-in functions are more than thousands of different types, including text class functions, digital class functions, database classes, graphics classes and so on, the function is very strong, it is upbraid tongue. But compared to programmers, how to make good use of these functions, with PHP syntax to write effective and well managed code, will be a big challenge.
Today, with the wisdom of pear, a world of top PHP pros, we can easily and efficiently write code and overcome many writing difficulties. In the case of martial arts circles, writing PHP with Pear is like hundreds of martial arts experts pouring their skills to programmers. Let program developers do not from the most basic training, yozakku horse-stance practice, borrow their skills can be very easy to multiply, efficiency doubled.
For half a day, what is pear? The next unit I will introduce.
The word pear literally means "pear".
A pear. The website of the official web site is
An example can be seen in the logo on the official Pear website.
The beginning of pear is from the November 1999 2l. A man named Stig S.bakken, who launched a project and called on a number of PHP pros to work together, first built some code base rules for the project, hoping that the PHP code that PHP's developers would write when they joined the project would need to follow these rules.
The project name is pear, which is actually the abbreviation for PHP Extension and application repository, meaning the continuation and application Library of "php, and simply put, pear is actually a PHP library.
The code base established by Mr. Bakken is as follows, and I'll just sketch it out and not talk about the details:
If a developer wants to provide a PHP library, the structure of the program must be object-structured.
The program's indentation should follow a certain format
The naming of classes in the program also follows a certain format
The code must be registered in a certain format
File naming should have a certain format
After the library is written, package packages will be packaged and the package will be packaged and installed in a certain format.
The project welcomes all PHP developers to develop PHP libraries together as long as they are willing to follow the code base rules described above. Mr. Bakken a group of teams as the controlling body of the project, responsible for reviewing the libraries provided by all the developers involved in the project and, if audited, categorizing the libraries and putting them on the official website for download by other developers, and the group is also responsible for maintaining and updating the official website.
Some people may be curious, why would anyone want to write a library for free and let others use it? This is the spirit of the open source world, a mutual aid, sharing. Imagine that if each developer uses a subset of its own specialized development libraries for others, and also enjoys the library of other developers, it is possible to achieve mutual assistance and allow each developer to share the results of all the developers. You don't have to write all the code yourself.
Even better, these libraries are available to people around the world for free, not just for developers who are involved in the development of the library (this approach is the same way as Java or Perl provides a function library).
Therefore, all the PHP developers around the world can save a lot of time to write code, but also because the use of library developers can return the library missing to the original developers, the original developers will continue to modify these libraries, so the code is relatively safe. In addition, the library developer will evolve with the times, adding new features to the library, allowing the library users to keep up with the times.
Detailed situation can be read in Pear's official website mentioned in the development of pear's purpose is to explain: I suggest you have time to see it slowly, and continue to read this article, you will slowly understand the magic of pear.
I have a chapter in the end of the article attached: Pear official website Introduction, we can first reference.
If you don't know what I mean by "library," it doesn't matter, and the next section will be explained by the actual example.
2-3 Introduction to All Kits
▓ Library vs Suite
Before we introduce all the kits, we have to clear two nouns to avoid confusing readers, one is "library" and the other is "suite".
If I were a PHP developer, I developed a database that can handle all of the database access "libraries" and would like to add this library to the world to share with pear. When I write the library of the finished database, I have to compress the library into a " "File, placed on the official Pear website for everyone to download, but also by following Pear's rules to compress files, this kit can be installed or managed using Pear's suite management instructions, which is quite handy for pear users, and for the package management instructions, I will complete the following section in the next chapter, believing that readers should know what "Library", What is "suite"? In fact, to put it simply, packing the library becomes a suite.
▓ Kits and Categories
Pear has released more than 300 kits so far, divided into 35 major categories, and is increasing. You can imagine the combination of the world's top PHP developers, is a lot of unity strength. The following image is a classification of the packages in the official web site:
Pear because of the release of too many kits, in order to manage the convenience so according to the function of the suite to classify the suite, the same class of packages in effect are relevant, but provide a different function is not the same small next, I will be all the classification of the form of a simple introduction, Let's learn more about what the Pear Suite can offer.
With so many classifications, each class will develop a different suite depending on the function. Take the first certification class as an example, if you go to the official website, you will find that there are currently 8 packages in the class
These 8 kits are related to the identity of the kit, if you want the Web page has the identity authentication function, for example, can let the Web browser to register, enter account password, identify, give permissions and so on. You will need to use these kits.
I would add that some of the packages have matured and the developers will call it the stable version, but if the library is still in development but it is already available, the developer will release it, often called the beta (Alpha or Beta) version. The official website also records the names of the developers and maintainers of the suite, and sometimes a suite is developed by many people.
These kits are available on the official website of pear, and my introduction to the official website of 〈pear will explain how to use the Pear official website.
2-4 simple examples of using the Pear Library
In this section, I use a simple example of l to illustrate the use of the library.
If you want to make a Web page and want to know how long it will take to execute the page, you can borrow the library named benchmark that Pear has released. The purpose of this library is to calculate the execution time of a Web page.
First, install the benchmark Library kit (please refer to the next chapter for installation method). Then we can start writing Web pages, for example: we've created a Web page called show.php.
Based on the convenience of speaking, I add the line number to the front of each stroke, we actually write the program without adding the line number.
Code 1th and Line 2nd first references the timer.php page in the benchmark suite, which contains the library that calculates the time of the page execution. Include_once can put an external page on this page, I call this action "reference", this example is equivalent to the implementation of the timer.php and show.php two pages.
Line 3rd, create a Benchmark_timer object with the New keyword and put the object in a variable named $timer. Then you use the start () method of the fine $timer object to start the clock, and then add my own code, which is a simple line of code.
Then it's time to end the clock, calculate how long the Web page will take to execute, and show it. Line 8th first uses the Stop () method of the $timer object to stop the clock, and the 9th line $timer object's timeelapsed () method calculates the time difference between the clock from the start to the stop and the result into the $totaltime variable.
Finally, we use the Echo function to display the time difference on the Web page.
It is clear from the results that the Show.php Web page took 0.00013613700866699 seconds from the start to the execution, and can then be judged by the number of observations to determine system performance or as a reference for code improvement. How to calculate the execution time is not convenient, fast and magical!
If you need to be on other pages can also have the ability to calculate the execution time of the page, as long as the above way to apply to other PHP pages on it.
In fact, the way other packages are used is also very different from the way the package is used. The difference is only in the classes, methods, and parameters used in each suite.
Although the package is easy to use, but believe that readers still have a lot of confusion? For example:
1. How does the benchmark Library suite come in? What predecessors do you want to work with?
2. How do I know the way to use the benchmark kit?
The 1th question concerns how to install the Pear Suite, as well as the management, upgrades, and erasure of the post installation package, which I will introduce in chapter 3rd. 2nd, I will make a detailed description of how to use the kit and how to get the information of the kit in chapter 4th.
2-5 Why do you use pear
Why do you use pear? According to my own experience, summed up the following points:
1. Save time and effort: Many of the code is written in the library, developers only need to reference the PHP file containing the library, you can have the library to provide the functionality, eliminating the time and effort to write themselves.
2. Security: Since these library suites are exposed to the original code, users who find bugs can be immediately reflected to the developer of the suite, and developers will often be corrected immediately to minimize the errors in the library.
3. Easy to maintain: Your own code is separate from the code in the Pear library, and if the Pear Suite releases a new version because of new features being developed or corrected, simply update the suite and not move to your own code.
4. Powerful: The Pear Suite offers a very large number of functions, in addition to common functions such as: Database links, profile processing, identity authentication, and form processing. In addition, the more advanced functions, such as Internet Post Office, network management, dynamic graphics, RSS, Wiki, or like phpBB BBCode parsing and so on can be simple.
5. Separate the programming of the Web page from the layout: Pear provides a library of many of the same boards that allow program development to be separated from the layout, making it easier for programmers to cooperate with web designers.
6. Learning PHP is an excellent example of learning: The library's annotations are very detailed, code writing, with certain rules and formats, and completely materialistic, so that developers easy to understand and learn. Some of the kits are also attached to teaching documents and examples, and most importantly: you don't have to spend half a dime on it, we should thank the authors of the package for their selfless contribution.
2-6 Why to set up the pear community
What is the reason for the world's PHP developers to join together to develop the program treasure of pear? I think there are several reasons for this:
1. The great strife of other contending people: this 1th chapter has already been stated.
2. The substance of PHP: from PHP4 to add material-oriented function, PHP5 is further materialized. In addition to with, jsp a spell, is convenient for the program modularization, so that the development of the library can be carried out, with the material function, the library can be written with the developer's own code cutting.
3. Common needs of developers: if every time you develop a PHP program, you have to do it from scratch, although you can exercise the program, but it is not efficient, not very economical. If some of the commonly used functions can be handled by the library, you can solve the difficulties of many developers. Based on the requirements that all developers share, let these PHP developers work together to develop libraries and help others.
2-7 PHP's competitors and pros and cons
PHP developed in the 1994, after four major rewriting, become what we see today can be widely used and mature products. By April 2005, PHP had been used on more than 19 million websites worldwide, and the number was growing fast.
PHP has the following advantages over their competing rivals:
High efficiency: Not my Huang Wa sell melon, haha ..., I have read many and JSP Web pages, the performance is really not compared with PHP. ( and JSP users should not read this article).
Can be tied to many different database systems: Other competing people can, but not PHP fast.
Easy to learn and easy to use: PHP code is very intuitive and easy to learn.
Support for object orientation: This aspect of JSP is strong, but PHP5 has been catching up.
Low cost: no money at all.
There are a lot of functions in the library: Remember the author used to use ASP, the built-in function library is very little pitiful.
Open source code: Security is higher than open.
Pear Library: This is the most recent powerful weapon used to fight against the enemy.
Availability: PHP is available for all types of UNIX operating systems, such as: Linux,freebsd, commercial UNIX or Windows operating systems. and JSP of course also have their unique advantages? For example, JSP is a powerful feature of Java, it can present some of the results that PHP cannot do. So JSP also attracted a lot of users, but the author of JSP current performance is not very satisfied with, on the contrary, the speed of the PHP is satisfied.
Using which program, you make a clear choice, however, if you choose to watch the article, I believe we should be fellow human, PHP enthusiasts.
In short, many of the PHP experts together to build a strong support network, if you are PHP programmer, but the good intentions of these masters ungrateful, it is not too bad?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.