Page 1 of 1

PEAR - Includes

Posted: Tue Mar 22, 2005 7:49 pm
by Ambush Commander
I've been looking at what Pear is about, and it sounds really, really cool. However, my webhost told me that they only have these packages installed:

Code: Select all

Installed packages:
===================
Package Version State
Archive_Tar 1.1 stable
Console_Getopt 1.2 stable
DB 1.6.2 stable
HTTP 1.2.2 stable
Mail 1.1.3 stable
Net_SMTP 1.2.6 stable
Net_Socket 1.0.1 stable
PEAR 1.3.2 stable
XML_Parser 1.0.1 stable
XML_RPC 1.1.0 stable
Which is only a smattering of what PEAR has to offer (I'm particularly interested in the BBCode Parser). However, I'm baffled as to how to include these files in my scripts.

According to what I gather so far, doing this:

Code: Select all

require "DB.php";
Will load the DB class. More delving revealed that this INI setting:

Code: Select all

ini_set("include_path", '/var/www/www.example.com/includes/' .PATH_SEPARATOR . ini_get("include_path"));
Is responsible for telling where to have the script look for an include file if the include fails for the directory.

I am now confused. Utterly confused.

Say I have a PEAR package named DB.php. I also, coincidentally, have a file in my working directory called DB.php

What do I do? If I want to call the PEAR package? If I want to call the DB.php from me?

And then, since I don't have root access to the server, I'll have to install the package in some top level directory seperate from the Include specified in the ini directory.

How do I include the files then (do I have to manually tell the script to go to that path, or can I like, change the ini setting? And if I change the ini setting, does that mean that I have to switch it back If I call a preinstalled package? Or should I just not bother using the already included packages and put everything in one place to stop myself from confusing myself?)

Posted: Tue Mar 22, 2005 8:06 pm
by feyd
typically, if you have some potential confusion with various scripts, you either rename them or pass the full path to include/require. Although I believe pear packages are named pear_<packagename> ...

from what I know, you can simply keep the packages you want to use in your own folders.. using ini_set() path only works for that page request, by the way.

Posted: Tue Mar 22, 2005 8:14 pm
by Ambush Commander
I'll probably ending up doing that(installing all the packages myself manually) (offers the most control over what I use and what I don't). Is there a bonus for installing it using PEAR's autoinstall tools?

Posted: Wed Mar 23, 2005 1:38 am
by timvw
php will look in the folders in your include_path just the way you add them.

thus if you have a include_path = '/dir1:/dir2' and you include 'file.php' it will first look for /dir1/file.php and if that is not found it will look for /dir2/file.php

the easiest is to install all the pear packages yourself. this way your webapp can't stop working if your webhost updates/changes the pear configuration.

so your include_path would look like '/home/user/pear:/usr/share/pear'. this way php will look in your local pear installation, and only after that in the system installation.

with a .htaccess that allows you to modify that php_value include_path you have the most power.

Posted: Wed Mar 23, 2005 2:21 pm
by Ambush Commander
Ah, so you can divide them with colons! That's very good, I now see what I can do. Very nice. That works. Although I'm probably going to do it with ini_set, because I don't know how to do it with HTACCESS.

Posted: Wed Mar 23, 2005 4:17 pm
by timvw
actually, it's : on a linux system. and ; on a windows system.

to avoid portability issues, you might want to use the magic PATH_SEPARATOR constant.

Posted: Wed Mar 23, 2005 4:18 pm
by Ambush Commander
Wow, thanks, that would have solved a problem I could have had!

So, this magical PATH_SEPERATOR constant is automatically there when you run scripts?

Posted: Wed Mar 23, 2005 4:21 pm
by timvw
together with all the others