Jump to content

Get Version Info

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
15 replies to this topic

#1
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
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, http://forum.codecal...-php-5-oop.html.

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:

<?php

//Echo the information page
//to the browser.
phpinfo();

?>

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.

Posted Image

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.

<?php

echo 'I am using PHP Version ' . phpversion();

?>

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.

Xav

+rep if useful; leave any comments/queries below!

Edited by Xav, 23 August 2008 - 11:42 AM.

Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
*ahem*
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
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. :)

#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Thanks. ;)

May I bring to your attention the very last line of my tutorial, in bold? :D
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#5
Guest_Jordan_*

Guest_Jordan_*
  • Guests
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:

# php -r "phpinfo();" | grep php.ini

replace php.ini with anything you want to search for (sorry Windows users, you'll have to browse through the HTML output).

This tutorial is fairly short and common knowledge. None-the-less it is formated well and does provide some valuable information. +rep

#6
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
I'd give you some more rep, if I could. :D Written very well :D +rep coming when I can again. :) Nice formatting also. :D

#7
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Cheers guys. :D

@Jordan: I didn't understand anything in your post except for the very last sentence. ;)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#8
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
In CLI you can also do
#php -v
In PHP you can also do
echo PHP_VERSION
No sense to use a function call when there is a predefined constant that does the same thing.

#9
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Erm, what's CLI mode?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#10
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Erm, I have no idea.

I got a pre-compiled server, so I have no idea. :)

#11
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Command Line Interface

In newer PHP (4.3.0+) CLI is what gets executed when running PHP from the console/command prompt/terminal. CLI has a lot of benefit over traditional CGI interface mode and Apache execution. With CLI it is possible to run a forked process (a thread) without the overhead of the Apache objects (since a fork makes a copy of its entire self). CLI also can a seperate php.ini file which allow you to change paramters such as max_execution_time. Those are just some of the benefits I can remember.

You can read more about it here: PHP: Using PHP from the command line - Manual

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Oh! I know all about the command line, but I never knew it got shortened to CLI! Ah, it makes so much sense to me now!
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums