Php 简明教程

PHP – PEAR

PEAR 是 PHP Extension and Application Repository 的首字母缩写。它是一个 PHP 包或扩展的存储库。您可以自由地在您的代码中加入任何这些来自 PEAR 的扩展。PEAR 项目是由 Stig S. Bakken 于 1999 年成立的。

PEAR is an acronym for PHP Extension and Application Repository. It is a repository of PHP packages or extensions. You can freely incorporate any of these extensions from PEAR in your code. The PEAR project was established by Stig S. Bakken in 1999.

大多数 PHP 预编译发行版(如 XAMPP)已经将 PEAR 捆绑在其中。如果没有,您可以通过从 https://pear.php.net/go-pear.phar 下载 go-pear.phar 文件并运行来安装 PEAR:

Most of the precompiled distributions of PHP such as XAMPP already have PEAR bundled with it. If not, you can install PEAR by downloading go-pear.phar file from https://pear.php.net/go-pear.phar and run

php go-pear.phar

在 Windows 命令提示符中,以开始安装。

In a Windows Command Prompt to start the installation.

根据您对安装步骤的响应,PEAR 包管理器将安装在您在安装期间指定的路径中。

Based on your responses to the setup steps, the PEAR Package Manager will be installed in the path, specified during installation.

然后,您可以将该安装路径添加到您的 PATH 环境中。可以手动完成此操作(开始 > 控制面板 > 系统 > 环境),或运行(双击)新生成的 PEAR_ENV.reg,它现在位于 PHP 源代码目录中。

You can then add that installation path to your PATH environment. Either do this manually (Start > Control Panel > System > Environment) or run (double-click) the newly generated PEAR_ENV.reg that’s now found in the PHP source directory.

您现在可以通过运行该命令来访问 PEAR 包管理器:

You can now access the PEAR Package Manager by running the command −

C:\xampp\php>pear

在 Windows 命令提示符中。

In a Windows Command Prompt.

您将按照以下方式获取 PEAR 命令的列表:

You will get the list of PEAR commands as follows −

C:\xampp\php>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
channel-discover       Initialize a Channel from its server
channel-info           Retrieve Information on a Channel
channel-login          Connects and authenticates to remote channel server
channel-logout         Logs out from the remote channel server
channel-update         Update an Existing Channel
clear-cache            Clear Web Services Cache
config-create          Create a Default configuration file
config-get             Show One Setting
config-help            Show Information About Setting
config-set             Change Setting
config-show            Show All Settings
convert                Convert a package.xml 1.0 to package.xml 2.0 format
cvsdiff                Run a "cvs diff" for all files in a package
cvstag                 Set CVS Release Tag
download               Download Package
download-all           Downloads each available package from the default channel
info                   Display information about a package
install                Install Package
list                   List Installed Packages In The Default Channel
list-all               List All Packages
list-channels          List Available Channels
list-files             List Files In Installed Package
list-upgrades          List Available Upgrades
login                  Connects and authenticates to remote server [Deprecated in favor of channel-login]
logout                 Logs out from the remote server [Deprecated in favor of channel-logout]
makerpm                Builds an RPM spec file from a PEAR package
package                Build Package
package-dependencies   Show package dependencies
package-validate       Validate Package Consistency
pickle                 Build PECL Package
remote-info            Information About Remote Packages
remote-list            List Remote Packages
run-scripts            Run Post-Install Scripts bundled with a package
run-tests              Run Regression Tests
search                 Search remote package database
shell-test             Shell Script Test
sign                   Sign a package distribution file
svntag                 Set SVN Release Tag
uninstall              Un-install Package
update-channels        Update the Channel List
upgrade                Upgrade Package
upgrade-all            Upgrade All Packages [Deprecated in favor of calling upgrade with no parameters]

使用 PEAR 安装软件包非常容易。寻找软件包的一种方法是使用官方 PEAR 站点 https://pear.php.net/packages.php ,然后运行

Installing packages with PEAR is so easy. One way to find packages, is using the official PEAR site https://pear.php.net/packages.php and then run

pear install <package-name>

下一步是在你的代码中使用 PEAR 软件包。为此,你应该在你的程序中使用 include、require、include_once 或 require_once 语句包含软件包的主要 PHP 脚本。

The next step is to use the PEAR package in your code. To do that, you should include the main PHP script of the package in your program with include, require, include_once or require_once statements.

<?php
   include "PEARPACKAGE.php";
   . . . . .
   // rest of the code
   . . . . .
?>

Composer 是一款较新的 PHP 软件包管理器,是管理 PHP 项目软件包的替代可用管理器。Composer 也支持 PEAR 软件包的安装。对于 PHP 软件包分发,许多人更喜欢 Composer 而非 PEAR。

A newer PHP package manager called Composer is an alternative available for managing packages for a PHP project. Composer also supports the installation of PEAR packages. Composer is preferred by many instead of PEAR for PHP package distribution.