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。

廣告