PHP – PEAR



PEAR 是 **PHP 扩展和应用程序资源库** 的缩写。它是一个 PHP 包或扩展的资源库。您可以自由地将这些扩展中的任何一个从 PEAR 并入您的代码中。PEAR 项目由 Stig S. Bakken 于 1999 年创建。

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

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。

广告

© . All rights reserved.