SiteCrafting, Inc.
PHP PEAR and include_path
When attempting to use the SMTP library from PEAR for a project, I was having problems with including the file. I kept getting a file stream error for this code:
require 'Net/SMTP.php';I figured the problem had to be related to the include_path setting in the configuration file.
When PEAR is installed, the include path in the PHP ini file is updated with the path to PEAR. Also, there's another path to the php folder, which is used by PEAR. So, if it's missing, PEAR includes will not work.
Here's an example of the master include path:
path = .:/usr/share/php:/usr/share/pear However, in the configuration, the ini_set( "include_path", "../include/"); overrides that setting, which prevents the require() function from working. At first, I figured I only needed to add the path for pear, so I tried setting the include_path this way.
ini_set("include_path","/usr/share/pear:../include/" );But that include failed also. That's when I figured out that PEAR also uses the "/usr/share/php" path and possibly the "." path, which is the path for the current directory.
Being the lazy programmer that I am, I didn't want to have to worry about updating these paths for different environment and settings, so I used this code snippet instead.
$strMasterInclude = get_include_path();
ini_set( 'include_path', "{$strMasterInclude}:../include/");Now, the paths required for PEAR will always be included, no matter the environment.
NOTE:
In this example, the file paths are separated by a colon ":", but the paths could also be separated by a semi-colon ";", depending on your setup.
by Ken Foubert | 4/18/2007 1:08pm | Comments (3)
There's also a php definition for the separator, so you could use that instead of hard coding the colon or semi-colon.
Example:
ini_set( "include_path", "{$strMasterInclude}" . PATH_SEPARATOR . "../include/");
Left by Ken Foubert | Oct 2, 2008
Just wish to say your article is as astonishing. The clarity in your post is just spectacular and i can assume you are an expert on this subject. Fine with your permission allow me to grab your feed to keep up to date with forthcoming post. Thanks a million and please keep up the gratifying work.,
Left by Birgit | Jan 25
As a website owner I believe the subject matter here is reallymagnificent. I thank you for your hard work. You should keep it up forever! Good Luck...,
Left by Quinton | Jan 27