SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: PHP::Pear

  1. #1
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    725
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Question PHP::Pear

    Hi

    Since Pear are just Classes written in PHP, why cannot we just use them directly in our code just as we include normal class pages? Why do we have to install the Pear package before using them?


    Thanx

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    But you can just use them as classes.

    You don't need to use the installer, you simply have to put them into a findable, include path. To make it easy for yourself that path should start at a folder called PEAR, and should be included in include_path directive in your ini file.

    I understand that you must have a copy of pear.php in the PEAR folder, but thats about it afaict. I am recent, cautious, convert to PEAR, never use the installer.

  3. #3
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    725
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    See, If I am on a shared server, I wont have access to the ini file, any alternate solution?

  4. #4
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, pear is just a collection of classes, but it also has a pear installer.
    Pear installer makes it easy to upgrade the class.

    How do you upgrade your so-called 'normal' php classes? You download a new version then copy it over your old version. With pear it's much better - you just run pear upgrade Some_Class
    It will do the upgrade for you but also keep track of dependencies and update its own internal registry, so the pear always knows which packages are installed.

    This is very important for dependencies resolution. So if you trying to install some pear package and pear installer determines that this package depends on another pear package that you don't yet have, it will ask you to install that one first or will automatically download and install the required dependency for you.

    Thank about it - when you get a new version of a software for windows (for example), you dont usually get a bunch of .dll files from a developer with instructions in which folder to copy each file, instead you run the installation program that does this for you.

    By the way, you can install pear without being root on your server, so technically on a shared server each user can have his own copy of pear.

    There is an instruction of a pear website of how to do this.

    http://pear.php.net/manual/en/installation.shared.php

    I have been using pear for years now and I will never even think about writing another project without it.
    Last edited by lampcms.com; Feb 2, 2009 at 05:51. Reason: Grandma (grammar)

  5. #5
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    725
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Question, How is pear better than Zend Framework or vice versa?


    Thanx

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Well at a pinch you can just stick the PEAR directory out of your doc root path and include() the files as normal.
    PHP Code:
    include( "../../PEAR/thispackage" ); 
    Or, whatever your include path is, include PEAR

    Or, ini_set( "include_path", "/var/www/includes/PEAR" );

    Or, stick the directive in a .htaccess file

    But seriously, get on to your supplier, adding PEAR to your include_path is pretty standard.

    Are you sure it isn't there, take a close look.

    var_dump( ini_get('include_path') );

  7. #7
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cancer10 View Post
    Question, How is pear better than Zend Framework or vice versa?


    Thanx

    All I know is I like pear. I looked at Zend framework once and did not like what I saw. I'm sure Zend framework is a fine framework, I just like pear better.

    Also there are more choices of classes in pear.

  8. #8
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PEAR are two things: It's a collection of classes and it's a package system. You can use one without the other; For example, you can install Zend Framework through their PEAR channel. You can also download PEAR classes manually and extract them to a folder and include them like any other php file.

  9. #9
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    725
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Question: Do I need to have mod_rewrite enabled if I am using Pear? I know this is one of the requirement when you are using Zend framework but not sure if this applies for Pear as well.

    Plz guide.


    thanx

  10. #10
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cancer10 View Post
    Question: Do I need to have mod_rewrite enabled if I am using Pear? I know this is one of the requirement when you are using Zend framework but not sure if this applies for Pear as well.

    Plz guide.


    thanx
    No, you dont need it for pear

  11. #11
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    725
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    k thanx for the info.

    I have been trying to implement pear without installation and directly including it to my present php file but I am failing each time.

    Why is this so complicated?

  12. #12
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because pear classes sometimes require other pear classes to be installed
    This is why you need to use pear installer instead of just copying classes by hand.

    When you use installer, it will check if a class depends on some other class and will also download and install dependencies for you.

    Also when a pear class requires another pear class it will just use
    include 'Some_Class/Some_file.php'
    it will work without the full path if you installed pear properly, but if you just copied the class by hand, then it will not work unless you also took some extra steps and modified your include path like this:
    set_include_path(get_include_path() . '/path/to/your/own/pear/');

    where the '/path/to/your/own/pear/' is where you copied all your pear classes.

  13. #13
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cancer10 View Post
    I have been trying to implement pear without installation and directly including it to my present php file but I am failing each time.
    Probably because you lack some dependencies. Each package from the PEAR repository has a download page, where you can download the raw package. This page also lists which other packages it depends on. You need to get those as well.

    It's a lot easier to just use the pear installer, since it will automatically resolve the dependencies for you. By default, PEAR installs into a global location, but you can install into a local folder, if you want. It's described in the documentation, but basically just log in through a terminal and run this command:

    Code:
    pear config-create /home/yourname/pear/ /home/yourname/pear/.pearrc
    Where /home/yourname/pear is the location for your local pear-installation.

    This will create a local installation.

    You can now install packages to this, using:
    Code:
    pear -c /home/yourname/pear/.pearrc install PACKAGENAME
    Where PACKAGENAME is the package you want to install.

    In your php scripts, you need to add the local installation to your include-path. This can be done in your scripts, using set_include_path as others have already explained.

    If you don't have shell access to your webserver, you can do all this on your local development machine, and the upload it through ftp.

  14. #14
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Why is this so complicated?
    I sympathize, and yet somehow I just don't.

    Open the files, look at the dependencies hardwired into the top of the classes and you will see the file structure all the PEAR classes need in order to sing and dance together nicely. i.e.

    /PEAR
    |- pear.php
    |-/Net/package2
    |-/Net/package

    But PEAR must be in your include_path

    Pear packages are very "Case Sensitive"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •