William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

php: php.ini

Here I write some notes about setting in php.ini. A little changes will make work easier and lazier.

1. pre-requirements
After install PHP env XAMPP, we can find where is the key configure file: php.ini:

All the following are from php.ini. Change some configures will make work easier and lazier.

2. Use <?=$variable;?> instead of <?php echo $variable;?>

For print a variable, use <?=$variable;?> instead of <?php echo $variable;?> seems a better point. Use of this shortcut requires short_open_tag to be on.

; This directive determines whether or not PHP will recognize 
; code between <? and ?> tags as PHP source which should be processed as such. 
; http://php.net/short-open-tag
short_open_tag = on

3. make available ‘tail -f ‘ $apache/logs/error.log.

; Besides displaying errors, PHP can also log errors to locations
; such as a server-specific log, STDERR, or a location specified 
; by the error_log directive found below.
; http://php.net/log-errors
log_errors = On

4. include_path not working?

PEAR library is default included in XAMPP, so from: http://localhost/xampp/pearinfo.php
we can get all PEAR info.

Right now suppose we want to code by using MDB2 package, like this:

require_once 'MDB2.php';
$dsn = 'mysql://test:test@localhost/test';
$mdb2 =& MDB2::factory($dsn);
if (PEAR::isError($mdb2)) {
  echo ($mdb2->getMessage().'-'.$mdb2->getUserinfo());
}
...

When running, there is always error:
Fatal error: Class ‘MDB2’ not found in …

It should be error regarding on path, because we already have PEAR. Check php.ini:

; PHP's default setting is ".;/path/to/php/pear"
; http://php.net/include-path
include_path = ".;C:\xampp\php\PEAR"

It looks correct: PEAR is already in the include_path. However, if we use:

print_r(get_included_files()); echo "<br>\n"; 

or:

set_include_path(get_include_path());
ini_set('include_path', 'C:\xampp\php\PEAR\MDB2.php');
print_r(get_included_files()); echo "<br>\n"; 

to test, the error is still there, the adding don’t work.

The reason: the ‘.;’ at the beginning of include_path setting is not working. They display in phpinfo(), but not active in codes.

So remove it, and change the setting like this:

include_path = "C:\xampp\xampp\php\PEAR"

Right now re-run the codes, it works.
This is only applicable in Windows env; if in Linux, it works fine.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: