views:

30

answers:

2

Hi,

I've just installed a PEAR package (Event_Dispatcher) and I can't use the classes in that package. When I run the command pear list I see the new package, however I see that the classes in the package are saved in /usr/lib/php (I have a Mac).

Is there a loading part after installing a PEAR package? How exactly do I move the files to the right place? Can I simply cut and paste the folder to the pear root folder?

Thanks!

A: 

Most PEAR packages have to be included via the usual include() and require() functions. They're not precompiled binaries, like (say) the MySQL driver (mysql.so/mysql.dll) are. As long as /usr/lib/php is in your include_path, PHP should be able to load up the package automatically when you do include('nameofpackage.php').

Marc B
Thanks for the reply. That might work, the only thing is I need to have the package in a specific folder, so I can roll out the code to production with the new classes included. I'm not using the PEAR classes only locally.
Cat
Is there any reason why you can't just install those PEAR packages onto the production server as well?
kguest
A: 

When PEAR is installed it usually automagically configures your php.ini to add the PEAR library path to the php.ini. Then, for each package, the authors will usually provide a file that will load the library for you which sits in the root of this PEAR lib directory.

For example, a PEAR package MDB2 has a load of different classes located under /MDB2, but there's also a PHP script at /MDB2.php, so all you need to do from your PHP code is this:

require_once("MDB2.php").

You'll obviously need to keep track of what you have installed on your local dev machine and make sure it's installed on the production server(s) too.

Sam Day