PHP Packages Installing PEAR Packages - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP Packages Installing PEAR Packages - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Thursday, July 18, 2019

PHP Packages Installing PEAR Packages

PHP Packages



Installing PEAR Packages

Problem

You want to install a PEAR package.

Solution

Download and install the package from the PEAR Channel server using Pryus:

       % php pyrus.phar install pear/Package_Name

You can also install from another PEAR Channel:

       % php pyrus.phar install channel/Package_Name

You can also install from any location on the Internet:

       % php pyrus.phar install http://pear.example.com/Package_Name-1.0.0.tgz

Here’s how to install if you have a local copy of a package:

       % php pyrus.phar install Package_Name-1.0.0.tgz

Discussion

To install PEAR packages, you need write permission where the packages are stored; this defaults to /usr/local/lib/php/.

You can also request multiple packages at the same time:

      % php pyrus.phar install pear/XML_RSS pear/XML_SVG
      Pyrus version 2.0.0a4 SHA-1: 72271D92C3AA1FA96DF9606CD538868544609A52
      Using PEAR installation found at /Users/rasmus/lib
      Downloading pear.php.net/XML_RSS
      Mime-type: application/octet-stream
      Downloading pear.php.net/XML_SVG=====================>] 100% ( 6/ 6 kb)
      Mime-type: application/octet-stream
      Installed pear.php.net/XML_RSS-1.0.2=====================>] 100% ( 7/ 7 kb)
      Installed pear.php.net/XML_SVG-1.1.0

When installing a package, Pyrus checks that you have all the necessary PHP functions and PEAR packages that the new package depends on. If this check fails, it installs all required PEAR dependencies:

       % php pyrus.phar install pear/XML_XUL-alpha
       Pyrus version 2.0.0a4 SHA-1: 72271D92C3AA1FA96DF9606CD538868544609A52
       Using PEAR installation found at /Users/rasmus/lib
       Downloading pear.php.net/XML_XUL
       Mime-type: application/octet-stream
       Downloading pear.php.net/XML_Util2===================>] 100% (26/26 kb)
       Mime-type: application/octet-stream
       Downloading pear.php.net/XML_Parser2==================>] 100% (16/16 kb)
       Mime-type: application/octet-stream
       Installed pear.php.net/XML_XUL-0.9.1====================>] 100% (11/11 kb)
       Installed pear.php.net/XML_Util2-0.1.0
       Installed pear.php.net/XML_Parser2-0.1.0

Once a PEAR package is installed, use it in your PHP scripts by calling require_once. For example, here’s how to include the HTTP_Request2 package:

       require_once 'HTTP/Request2.php';

Generally, if a package name contains an underscore, replace it with a slash, and add .php to the end.

Because PEAR packages are included as regular PHP files, make sure the directory containing the PEAR packages is in your include_path. If it isn’t, include_once and require_once can’t find PEAR class files.

No comments:

Post a Comment

Post Top Ad