Hello, Xav again. In this tutorial we are going to see how to retrieve information about the version and components of your PHP installation.
Introduction
There are lots of different features in PHP that exist only in certain versions of PHP. For example, Object Oriented Programming (or OOP for short) was revamped in version 5, even though it has existed since PHP version 3. You can read more about PHP 5's object oriented features in Jordan's tutorial, PHP 5 and OOP.
The strange thing is, in quite a few hosting packages, companies don't actually disclose much data about the PHP installation. For example, in my 1&1 package I had no idea which version of PHP I had installed, as the signup page simply said "PHP 4 & 5".
Getting your PHP Version
Thank goodness PHP has addressed this problem. There is a function called phpinfo(), which tells you your PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and, of course, the all-important PHP License. It is incredibly simple to use.
1. Create a blank page and call it info.php. Open it in any editor of your choice and type the following code:
And that's it! Note that phpinfo() can return a boolean value relating to the success or failure of the operation. Load the page up under your local server (or online server if you're using one) and you should see a page containing all the information you need.Code:<?php
//Echo the information page
//to the browser.
phpinfo();
?>
Note, however, that you can also use phpinfo() with a single parameter, $with, as well. For more info on these bit-packed constants, see PHP: phpinfo - Manual for more details.
Just the PHP Version, please
If you want, you can just retrieve the PHP Version on its own, without the other stuff. To do this, just use the built-in phpversion() function.
Again, phpversion() can be used with a single parameter, this time a string argument denoting the name of the extension to the return the version for. Visit PHP: phpversion - Manual for details.Code:<?php
echo 'I am using PHP Version ' . phpversion();
?>
Xav
+rep if useful; leave any comments/queries below!
Last edited by Xav; 08-23-2008 at 12:42 PM.
Very useful and simple code to know a lot about your PHP installation. I didn't actually know about phpversion() function. I like how it tells you about your execution time, and enabled extensions.
Again great tutorial xav.![]()
You can also use this in CLI mode with grep for some handy info. For instance, say you wanted to find where php.ini is located (and your CLI version does not use a different php.ini than your web version) you could execute this:
replace php.ini with anything you want to search for (sorry Windows users, you'll have to browse through the HTML output).Code:# php -r "phpinfo();" | grep php.ini
This tutorial is fairly short and common knowledge. None-the-less it is formated well and does provide some valuable information. +rep
I'd give you some more rep, if I could.Written very well
+rep coming when I can again.
Nice formatting also.
![]()
In CLI you can also doIn PHP you can also doCode:#php -vNo sense to use a function call when there is a predefined constant that does the same thing.Code:echo PHP_VERSION
Erm, I have no idea.
I got a pre-compiled server, so I have no idea.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks