1. Introduction to PEAR
PEAR: PHP Extension and Application Repository, PHP extension and application library. (Suddenly I want to eat pears)
Pear's mission: Provide reusable components and lead PHP innovation.
Packages and applications that provide PHP code.
Pear is also a PHP code standard, making PHP code easier to read and improving reusability.
2. PEAR installation
When installing php, pear will be installed by default, in the bin directory.
Use the version parameter to view the version number.
$ ./pear version
PEAR Version: 1.9.4
PHP Version: 5.4.26
Zend Engine Version: 2.4.0
Copy after login
Verify the include path of php
The pear extension is installed under the include path of PHP.
$ ./pear config-get php_dir
/home/gang/php/lib/php
Copy after login
3. pear parameter
Running pear directly will output its parameters.
$ ./pear
Commands:
build Build an Extension From C Source
bundle Unpacks a Pecl Package
channel-add Add a Channel
channel-alias Specify an alias to a channel name
channel-delete Remove a Channel From the List
...
Copy after login
Commonly used parameters:
info View package information
install installation package
uninstall uninstall package
list View locally installed packages
remote-list View online packages
upgrade upgrade package
config-show View config configuration
Check the usage of common parameters through help
$ ./pear help install
Copy after login
4. Install php package
For example, we need to install the LOG package
$ ./pear install LOG
Copy after login
After successful operation, Log.php and Log directories, as well as the doc directory will be generated in the php/lib directory.
There are usage examples and instructions under doc/Log.
Upgrade LOG package:
./pear upgrade LOG
Copy after login
5. Use of installation package
The Log package we installed above.
Just require it in the application's php code.
<?php
require_once 'Log.php';
$logger = Log::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'ident');
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
Copy after login
6. Commonly used php packages
PHPDoc – Document Extraction Tool
PHPUnit – unit testing framework
DB – database package
All can be viewed using the command:
$ ./pear remote-list
Copy after login
http://www.bkjia.com/PHPjc/755763.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/755763.htmlTechArticle1. Introduction to PEAR PEAR: PHP Extension and Application Repository, php extension and application library. (Suddenly I want to eat pears) Pear's mission: to provide reusable components and lead the innovation of PHP. Provide...