Home php教程 php手册 php 什么是PEAR?(第二篇)

php 什么是PEAR?(第二篇)

Jun 13, 2016 pm 12:24 PM
pear php What Library yes Introduction

▓ 套件简介
PEAR最重要的就是拥有许多的程式库可供开发者免费引用,这些程式库会被包裹成套件,而且每个套件中都会放入一个名为package.xml的档案.这是PEAR团队的规定,这个档案纪錄著程式库的档案架构,版本编号等资料,有了这个档案,程式库压缩后才有资格称为「套件」,也因为有了这个xml档,PEAR所提供的「套件管理指令」就可以很简单地管理程式库,例如:可以用指令来安装套件、刪除套件、观看套件资讯或套件升级等。
另外.关於套件的安全性方面,使用者若发现套件有问题,可以借由论坛加以讨论或回报给开发团队,他们就会快速的进行修正与改版,也因此每个套件都会有版本编号加以区分改版的过程。
详细內容请参閱〈附錄A.PEAR官方网站介绍〉会有收获的。
注意,若大家按照本文章的范例操作时,如发觉结果与我们介绍的内容有所不相同的地方,请不要觉得奇怪,那是因为PEAR套件更新的速度太快所致,我们所介绍的方法与原意是不会变的,只是过程会随套件的更改而变动。
▓ 如何得知套件的相关资讯
想下载套件或了解套件,读者可以进入PEAR官方网站(网址为http://pear.php.net)
圈选的超连结是放置套件的所在
1号圈圈所在较粗黑的字代表套件的类別,例如:第1类叫做认证类(Authentication)。这个类別目前包含8个套件,这些套件都是用来处理登入与登出或身份认证与权限设定等。
2号圈圈所在较小的字代表套件的名称,如:Auth、Auth HTTP等等。大家可点选各套件名称进入观看更详细的套件资讯或下载套件。
至目前为止,PEAR的套件共有35大类,三百多个套件,开发套件的成员共202人,但这些数字都在持续增加中,若大家将来有一天,也想为PEAR社群的一员贡献一己之力,也可申请成为套件的开发人员。
要使用PEAR程式库,需要有以下几个基本步骤:
1.架设好网页伺服器,例如Apache,並安装好PHP与MySOL。
2.必须安装PEAR的一些基本套件,所谓的「基本套件」 就是所有PEAR套件都需要的套件,例如,除错是每一个套件都需要的,所以基本套件中就包含了除错套件,只有先安装除错的套件,其它的套件才可以顺利进行除错。
3.针对开发者的需求,安装特定的套件。例如,安装完基本套件后.若开发者想在网页中加入计算执行时间的功能,就必须用指令安装Benchmark套件,这个套件不是基本套件,必须由开发者自行安装。
4.在PHP程式中引用套件的程式库档。
以下我们来分別介绍,在Windows作业系统与类Unix作业系统下,如何安装与管理PEAR套件。
3-2 在Windows系列作业系统上PEAR的安装与管理
▓ 安装Apache+PHP+MySQL
如果您尚未建置好PHP的执行环境,建议您安装AppServ这套六合一软体,笔者就是使用AppServ来当作windows的伺服器环境。这个软体可以到http://www.appservnetwork.com/官方网站去下载。
▓ PEAR的安装方法
安装好AppServ后,就可以开始在Windows上安装PEAR的基本套件,安装过程可以分为四个步骤。
第1个步骤:进入http;//go-pear.org/网站
请先连上http;//go-pear.org/的网站
接着,将网页中的文字完全复制起来后,打开系统的附属应用程式中的记事本,将刚刚复制好的文字贴上,贴上后将档案储存于C:AppServ\www,也就是网站根目录的位置,存挡时请注意,存档类型请选所有档案,副挡名需要为php,档名请自行命名,假设我自定存档名为pear.php,如下图:
如果您不想怎么麻烦,也可以用Dreamweaver之类的网页编辑软件,打开一个空白的PHP档,然后将http://go-pear.org复制的文字贴上并存档。
第2个步骤:安装基本套件
打开浏览器,在网址栏输入“http;//127.0.0.1复制go-pear网站档.php”或“http;//localhost/复制go-pear网站档.php”,其中所谓「复制go-pear网站档.php」就是刚刚复制储存复制文字的档案名称,在本范例中为pear.php,所以我输入“http;//127.0.0.1/pear.php”,即可出现线上安装PEAR的网页
第一个画面是欢迎画面,我不多做介绍了。请按NEXT >>,进行下一步的安装步骤
这一页是用来设定PEAR套件的安装位置,最上端有一个HTTP proxy栏位,若安装者需透过proxy才能连上网路,请将proxy的IP与port号填写在此,若沒有使用proxy,此栏位可保持空白。接著有l0项安装路径的设定,谙特別注意,其中有3个路径必须修改,分別为:
1.第l项的Install prefix,请将预设的c:AppServ﹨www改为c:AppServ﹨php,因
为我希望被安装的PEAR程式库,不要放入www中与根目錄的网页混杂在一起。
2.第9项的Filename of WebFrontend,请将预设值改为c:AppServ﹨www﹨pear﹨index.php。意思是在www中產生一个名为pear的资料夹,资料夹內的index.php是系统產生的套件管理介面,这个介面后面会提到(为防后面的操作失败,请先在C:AppServ﹨www中建立一个名为pear的资料夹)。
3.第10项的php.exe path需改为c:AppServ﹨php﹨php.exe,也就是需指定正确的php.exe档的所在位置。
其余的设定都用预设值就可以了,我在这里简单介绍一下其他设定项的意义:
● 第2项的Binaries Direetory,是将第一项的c:AppServ﹨php指定为PEAR的根目錄,並用变数$prefix来代表。
● 第3项的PHP code Directory,就是PEAR套件被安装后档案所放置的位置。本范例PEAR套件被下载后的档案会被安装在c:AppServ﹨php﹨PEAR中。
● 第4项是如果被安装的套件有內附的說明文件,本范例会放在c:AppServ﹨php﹨PEAR﹨docs中。
● 第5项足如果被安装的套件有內附的范例档,本范例会放在c:AppServ﹨php﹨PEAR﹨data中。
● 第6项是如果被安装的套件有內附的测试档.本范例会放在c:AppServ﹨php﹨PEAR﹨test中。
● 第7项是PEAR的cache档放置的位置,本范例会放在c:AppServ﹨php﹨PEAR﹨cache中。
● 第8项是快取(Cache)档的壽命,本范例快取档的壽命是300秒,也就是300秒后会重新快取。
另外,需注意的一点是网页的阅览者须对这些路径具有写入的权限,否则无法安装。
设定项修改完后,按最小方的install按钮,即可进行安装
当最上方的安装进度达到100%时,恭喜您,您已完成了基本套件的安装。根据我使用ADSL下载速度2M的环境下测试,大約2分钟即安装完毕,若大家的网路连線速度不夠快,或在安装到一半时连線中断,请按浏览器上方的重新整理钮或按F5即可重新安装。
安装完毕之后.请大家别先高兴,PEAR共有三百多个套件,目前为止只是安装了PEAR的基本套件而已,並沒有安装所有的套件,基本套件以外的其他套件则等到开发者需要使用时再逐一安装。
大家可能会问:「那其他套件如何安装? 会不会很麻烦?」大家请放心,这並不麻烦,下一个小单元中将会针对套件的安装与管理做详细的介绍。
安装完基本套件后,进入c:Appserv﹨php中将会发现有一个名为PEAR的资料夹,该资料夹即为套件经下载並解压缩后,程式库所放置的路径所在
对大家而言,其中的docs与tests这两个资料夹內会有学习PEAR的好东西喔。有些套件会內附使用教学文件,若使用者安装该套件后,教学文件就会放在docs资料夹中。而有些套件则是內附范例程式,使用者安装套件后,范例程式会出现在tests资料夹中
▓ PEAR套件的管理
安装完基本套件后,当开发者需要使用基本套件以外的其他套件时,会需要安装套件,若不需要某个套件时,就会想要移除套件,若套件版本过於老旧,则需要升级套件,也就是說开发者需要一套PEAR套件的管理系统。
在Windows作业系统下的套件安装与管理可以有两种方式,一种是使用Web的管理介面,另一种足使用「套件指令」。笔者较为推荐后者,因为执行的速度较快,但若您对指令有畏惧感,也可以用第一种来轻松管理套件。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles