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 环境中。手动执行此操作(>> 系统> 环境控制面板启动)或运行(双击)现在在 PHP 源目录中找到的新生成的 PEAR_ENV.reg。
现在,您可以通过运行以下命令来访问 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]
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";
. . . . .
// 其余代码
. . . . .
?>
名为 Composer 的较新 PHP 包管理器是可用于管理 PHP 项目的包的替代方法。Composer 还支持安装 PEAR 包。许多人更喜欢 Composer 而不是 PEAR 来分发 PHP 包。