View Full Version : Query Server for Apache version only
Boofo
03-07-2004, 04:23 AM
Can someone please tell me why I get an undefined function error when running this code in the functions.php? I want to query the server for the Apache version without getting the long string you get using SERVER_SOFTWARE.
$apacheversion = apache_get_version();
Andreas
03-07-2004, 04:53 AM
apache_get_version() is only available in PHP version > 4.3.2, so this might be the cause.
Try this snippet:
$ar = split("[/ ]", getenv("SERVER_SOFTWARE"));
$apacheversion = $ar[1];
Boofo
03-07-2004, 06:38 AM
Thank you, sir. That worked great! ;)
The server I am on is running PHP v4.3.3. I'm not sure why that code I posted doesn't work. It should have. :surprised:
Is there also a way to get the version of UNIX or Linux (as my server has)?
NTLDR
03-07-2004, 04:25 PM
Is apache running as a module or as CGI? As apache_get_version() only works if its run as a module.
Boofo
03-07-2004, 08:22 PM
You got me on that one. I have no idea which way they have it set up. Apparently, it must be set up as CGI since the script gives me the unknown function error, right? :) Is one way really any better than the other?
Also, is there a way to pull the Linix version number out, too?
NTLDR
03-07-2004, 09:22 PM
Apache as a module is the better method to use, take a look at the Server API part of phpinfo() at the very top and it should say Apache if your running it as a module.
For the Linux version info, provided you can run shell_exec() you can get the OS info with:
$info = shell_exec('uname');
There are various options to add to get different stuff:
Usage: uname [OPTION]...
Print certain system information. With no OPTION, same as -s.
-a, --all print all information
-m, --machine print the machine (hardware) type
-n, --nodename print the machine's network node hostname
-r, --release print the operating system release
-s, --sysname print the operating system name
-p, --processor print the host processor type
-v print the operating system version
--help display this help and exit
--version output version information and exit
The info will be returned in the $info variable. I'd advise against making this information publicly available though ;)
Boofo
03-07-2004, 09:48 PM
Is there such a thing as this for the Linux version?
#1 SMP Mon Aug 18 14:34:09 EDT 2003
That's what it returns.
I only have this info displayed for Admins. It is not available to the other users. ;)
The Server API just says Apache.
NTLDR
03-07-2004, 10:04 PM
If you mean the Linux Kernel version then uname -r is what you want.
I've just tired apache_get_version(); on my server and it seems to work correctly for me with the Server API as Apache (ie a module), however, I think what you get returned from that is the same as you'll get from getenv('SERVER_SOFTWARE'); as both return Apache for me as I've set it to not show any other details in httpd.conf.
Boofo
03-07-2004, 10:18 PM
It must be running as CGI on my server then. That would explain why I get the error. The code KirbyDE posted above gave me just the version number of Apache and nothing else. That's all I needed as I already have the other info.
I tried the -r and this is what I got:
2.4.20-20.7smp
Does that look right to you? What does the smp stand for?
What is the exact code you used with this? apache_get_version();
NTLDR
03-08-2004, 09:54 AM
Yes, that looks right ;) The SMP (symmetric multiprocessing) part means your kernel has been complied to support more than one CPU.
I just did:
<?php
echo apache_get_version();
?>
Which gave me the same result as what I see on my phpinfo() page for the SERVER_SOFTWARE variable.
Boofo
03-08-2004, 10:31 AM
This is what I get when I try to run it:
Fatal error: Call to undefined function: apache_get_version() in XXXXXXXXXX :(
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.