Monday, May 30, 2011

Some PHP commandline options


#php --ri date
date
date/time support => enabled
"Olson" Timezone Database Version => 2009.20
Timezone Database => internal
Default timezone => Europe/Oslo
Directive => Local Value => Master Value
date.timezone => Europe/Oslo => Europe/Oslo
date.default_latitude => 59.930972 => 59.930972
date.default_longitude => 10.776699 => 10.776699
date.sunset_zenith => 90.583333 => 90.583333
date.sunrise_zenith => 90.583333 => 90.583333

Some other php-cli options,

--rf Show information about function .
--rc Show information about class .
--re Show information about extension .

This option is only available if PHP was compiled with Reflection support.

1)

#php --rf var_dump
Function [ public function var_dump ] {
Parameters [2] {
Parameter #0 [ $var ]
Parameter #1 [ $... ]
}
}

2)

#php --rc Directory
Class [ class Directory ] {
Constants [0] {
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [0] {
}
- Methods [3] {
Method [ public method close ] {
}
Method [ public method rewind ] {
}
Method [ public method read ] {
}
}
}

3)

#php --re json
Extension [ extension #19 json version 1.2.1 ] {
Functions {
Function [ function json_encode ] {
}
Function [ function json_decode ] {
}
}
}

4) Using a different php.ini file

The following option can be useful when you need to test various ini configurations, or you need to check if all the modules in a particular ini are loading correctly.

#php –c PATH/to/PHP.INI example.php

5) Check to see for any syntax errors in a php file

Need to quickly check for php syntax errors if you do not have access to an IDE, then this option can be quite helpful. Combine it with some shell code and you can easily check for syntax errors for multiple files in a directory.

#php –l example.php

6) Display php built-in and loaded modules with debug

Combine it with php –c to debug any module loading errors for different php.ini files

#php –c PATH/to/PHP.INI -m

7) Syntax Highlighting

The following option will display syntax highlighted text using php’s internal mechanism.

#php –s example.php

You can then write the output to another file using a redirect.

#php –s example.php > syntax.html

8) Strip the source code of comments and whitespace

Can be useful if you need to reduce the file size.

#php –w example.php

No comments: