PDA

View Full Version : PEAR example please



lloydlegacy.net
02-13-2008, 07:45 AM
Does anyone have a specific example of using a PEAR module in the BlueHost environment?

There are some great PEAR posts in this forum (for example, srowley's response to andeg's "PEAR DB problems" post), but I can't seem to take the concepts to "instantiation".

Here is what I'd like to see: (Any PEAR module will do.)

(1) What change I would need to make to my php.ini file. And how many php.ini files would I need to define (e.g. one for each folder path?)
(2) How I could find if a PEAR module exists for my problem and where its documentation exists within bluehost.
(3) What, specifically, are the code snippet(s) that would appear in a PHP5 Class within a try-catch statement.

My domain name is lloydlegacy.net. The main folder I use is /public_html/legacy/ which contains a php.ini, my index.html and index.php as well as folders for each of my main modules (e.g. addressbook, albums, article, ... , signin).

I do use classes and inheritance (within Patterns).

I can't believe I'm this illiterate.

Regards,

Poppa Brian

charlesp
02-14-2008, 11:25 PM
http://pear.php.net/manual/en/

I actually have a couple of examples but they don't work on BH. They work on my home system but not BH.

I don't kknow if they can't find the modules or what.

lloydlegacy.net
02-15-2008, 01:39 PM
Thank you. I have downloaded the manual. But, as you seem to suggest -- as do the others in this forum -- the BlueHost implementation is not clear.

charlesp
02-16-2008, 02:04 PM
I got my pear modules to work. I had to change my include path in my phpini.
see this post http://bluehostforums.com/showthread.php?t=8963

fwerginz
02-17-2008, 07:46 AM
This isn't an example of how to use PEAR but it is an example of how to get around not being able to use it.

I had the need to install a PHP package and one of the first things I did was search the forum for some guidance. What I discovered was that there a lot of questions about how to use PEAR from cPanel and not a lot of answers. In fact, I’m left wondering if PEAR on cPanel works at all. I never got it to work and it doesn't seem anyone else has either or they're not talking.

I wanted to install Creole (http://creole.phpdb.org/), a common database API that lets you write your application in such a way that it should port to a different db vendor in the future without requiring code changes. The application I’m working on is currently using MySQL but it may eventually use Oracle as parts get moved to another server not on Bluehost (for technical reasons not one of any dissatisfaction with Bluehost :) ).

Reading the installation instructions on the Creole web site (http://creole.phpdb.org/trac/wiki/Documentation/Installation), the procedure shows how to install the API using PEAR with these commands:


$> pear channel-discover pear.phpdb.org
$> pear install phpdb/creole
$> pear install phpdb/jargon


That didn’t do a lot of good for me since I don’t have ssh access to the Bluehost server. I tried like crazy to use figure out how to use the PEAR interface on cPanel to install Creole but got nowhere.

The Creole site also has these instructions for a non-PEAR install:


$> cd /path/to/creole
$> ln -s classes/creole /usr/local/lib/php/creole
$> ln -s classes/jargon /usr/local/lib/php/jargon


Again, this doesn’t do much good since these are more Unix commands to do from the shell. But, this provided the best clue as to what I would eventually have to do.

I downloaded the Creole package to my PC, unzipped it and looked at the directories and some of the php code. Then I read through the Creole User Guide online. To use the Creole classes one needs to do a require_once 'creole/Creole.php' in each PHP file that make a reference to the API. It wasn’t until I read the forum thread mentioned above (http://bluehostforums.com/showthread.php?t=8963) that I started to understand how to hook things together. It helped me understand that at runtime, php will look into directories named in the 'include_path' in php.ini (located in my web root directory /www). Easy enough, I added /home/[my_user_name]/php.

Next, I copied the entire Creole package that I downloaded and unzipped on my PC to the directory /home/[my_user_name]/php. That left me with a directory structure that looked like this:


/home/[my_user_name]/php/creole

In that directory were several sub-directories including one called classes. Not knowing if there was some magic in how classes are resolved, I made the assumption that PHP somehow knew to drill down the directory tree (i.e. creole/classes/creole/Creole.php). Wrong!

One solution would be to add the complete path to Creole in 'include_path'. That just doesn’t seem like the right thing to do though and could make a real mess of the include_path parameter as other packages are added. Since the require_once directive is trying to load Creole.php from a directory named ‘creole’, it told me that Creole.php needed to be in the path:

/home/[my_user_name]/php/creole/Creole.php

This is where the non-PEAR install instructions on the Creole site came in handy. According to those instructions, there needs to be two directories, creole and jargon. It seems that everything in the downloaded package doesn't need to be on the server. Instead of copying the entire unzipped Creole directory tree from my PC, I copied only the two sub-directories 'creole' and 'jargon'. With that, the require_once directive was able to find creole/Creole.php.

I don’t know if this will work for every package or if PEAR does something other than just copy the right files to the right places. Hopefully, someone will be able to comment on that.

lloydlegacy.net
02-17-2008, 06:09 PM
Guys, I'm not following you on the specific changes I'd need to make. to my PHP.INI. Allow me to repeat my request



Here is what I'd like to see: (Any PEAR module will do.)

(1) What change I would need to make to my php.ini file. And how many php.ini files would I need to define (e.g. one for each folder path?)
(2) How I could find if a PEAR module exists for my problem and where its documentation exists within bluehost.
(3) What, specifically, are the code snippet(s) that would appear in a PHP5 Class within a try-catch statement.



I did check out http://bluehostforums.com/showthread.php?t=8963 but still am not sure what I need to do short of downloading the full PHP library into my own domain. And that can't be right.

Don't get me wrong, I really appreciate your comments, I'm just not familiar enough with the mechanics.

charlesp
02-17-2008, 11:17 PM
The only real change that I made was from the link you look at. And that is the change to my php.ini file like this:

include_path = ".:/usr/lib/php:/usr/local/lib/php:/home/yourusername/php" ;

But after I deleted the file and uploaded it again it did not work and I am not sure why. I am taking some time away from my studies tonight and am working on it again. I should be able to get it to work again since it worked before. But I have to admit that bluehost doesn't make it that user friendly.:D

Edit: I just tried it and it works again with no error codes or anything. The first try I got the result I was looking for.

charlesp
02-17-2008, 11:51 PM
(1) What change I would need to make to my php.ini file. And how many php.ini files would I need to define (e.g. one for each folder path?)
(2) How I could find if a PEAR module exists for my problem and where its documentation exists within bluehost.
(3) What, specifically, are the code snippet(s) that would appear in a PHP5 Class within a try-catch statement.

(1)I showed you the change that I made to my php.ini file. My test files are in public_html folder and that's the only place that I changed the php.ini.

(2)To find if a PEAR module exists I looked in /home/username/php. If you drill down far enough there is a folder called 'docs'. (/home/username/php/docs/Auth/examples/logging.php) In there is an example of a script called logging.php. You can copy that and run it in your folder to see how it works. You can install PEAR packages in the cPanel under Software/Services - PHP PEAR packages.

(3) I don't know:o