Php 简明教程

PHP – PEAR

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

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

php go-pear.phar

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

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

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

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

C:\xampp\php>pear

在 Windows 命令提示符中。

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

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 ,然后运行

pear install <package-name>

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

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

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