jMar"s Blog DevSmash Developer Portal

Tuesday, April 22, 2008

Know Your Environment: PHP Server Module Reporter

This post was authored by David Walsh. To learn more about David, click here.

One of the unfortunate parts on my job is that I rarely get a say in the customer's hosting environment. We don't host our customers' sites so I'm usually at the mercy of whichever hosting provider the customer has contracted with. We usually try to steer our customer toward our preferred host, but most of the time the customer is reluctant to switch because they fear email issues and change in general.

Knowing the hosting environment's limitations before we begin to develop the website is a must. Imagine creating a great website and running into issues later on because the shared hosting server doesn't have a given extension installed. A nightmare!

I've created a basic PHP script that I simply FTP to the server and use to evaluate extensions on the server. I simply supply the extensions I require and the script does the rest of the work.

 /* set required extensions */
 $my_required_extensions = array(
  'gd',  //graphics library
  'xml',  //xml
  'mysql', //database
  'curl',  //networking
  'openssl', //site will need SSL
  'pecl'  //pear
 //get loaded modules
 $loaded_extensions = get_loaded_extensions();

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en" lang="en">
 <title><?php echo $source_article; ?> Example</title>
 <meta name="description" value="<?php echo htmlentities($meta_description); ?>" />
 <style type="text/css">
  body  { font-size:12px; }
  h2   { border-bottom:1px solid #ccc; font-weight:normal; font-size:18px; margin-bottom:5px; padding-bottom:2px; }
  p   { line-height:20px; margin-top:0; }
  .found  { background:lightgreen; padding:5px 10px; margin:0 0 10px 0; }
  .miss  { background:pink; padding:5px 10px; margin:0 0 10px 0; }
  .extra  { background:lightblue; padding:5px 10px; margin:0 0 10px 0; }

<h1><?php echo $_SERVER['HTTP_HOST']; ?></h1>

<h2>General Information</h2>
 <strong>Server Software:</strong>  <?php echo $_SERVER['SERVER_SOFTWARE']; ?><br />
 <strong>Document Root:</strong> <?php echo $_SERVER['DOCUMENT_ROOT']; ?><br />
 <strong>PHP Version:</strong> <?php echo phpversion(); ?>

<h2>Extension Check</h2>
 /* print out */
 //analyze results
 foreach($my_required_extensions as $ext)
   $matches[] = strtolower($ext);
   $missings[] = strtolower($ext);
 //print out results
 natcasesort($matches); natcasesort($missings); natcasesort($loaded_extensions);
 foreach($matches as $match) { echo '<div class="found"><strong>',$match,'</strong> found!</div>'; }
 foreach($missings as $miss) { echo '<div class="miss"><strong>',$miss,'</strong> missing!</div>'; }
 foreach($loaded_extensions as $e) { if(!in_array($e,$matches) && !in_array($e,$missings)) { echo '<div class="extra"><strong>',$e,'</strong> is available.</div>'; } }
?><br />


The output looks as follows:

Extension Evaluator Screenshot
(click to enlarge)

If I run into the situation where a needed extension isn't there, I must decide whether to push for the customer to switch hosts or adjust the way I code the website. You'll also want to keep a copy of this on hand so that you have proof when the host changes the server and causes issues with the website. Happy coding!

David Walsh.David Walsh is a Senior Web Developer residing in Madison, WI. He spends most of his day getting a monitor tan coding PHP, CSS, MooTools, and XHTML. When not tinkering with the newest version of Moo, David uses soccer, Rock Band, and movies to dull his coding pains.


Jesus said...

What about your mysql version? Though I am not sure how to get this without phpinfo() or knowing how to connect to the database in advance.

Nice script though

David said...

Great suggestion Jesus! To get the MySQL version, you could add:

echo("MySQL server version: ". mysql_get_server_info());

CédricG said...

If there is zero missing extension I have a big error* about $missing does not exists.
But nice idea!

*yes, I have XDebug ;-)

David said...

@CédricG: How luck you are to not be missing any extensions! Use the prevent that error:

if(count($missings)) {
foreach($missings as $miss) { /* code here */ } }

terminals-blocks said...

I have a big error* about $missing does not exists

admission essay writing service said...

Great information you have shared. Thanks for your informative post. The essay is one fraction of your application over which you have total control.

aliya seen said...

The university statement of purpose is perfect for students who are really needed of some programming and love to be part of it.

Anita Romanenko said...

Really structured and useful information. And everything is clear, thanks. I looked through some posts and must say, they are very interesting. Best regards, essay writer.

Annie Gilson said...

Impressive writing skills! This information is truly seeking for a while and very respective content. Thanks
Walking dead jacket on

Watch Zootopia Online full movie said...

Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading.

Watch London Has Fallen Online full movie | Watch Whiskey Tango Foxtrot Online full movie

Friv said...

I am satisfied that you shared this useful info with us. Please stay us informed like this.

Deny Games said...

I love all the posts, I really enjoyed, I would like more information about this, because it is very nice. Thanks for sharing.
juegos de friv | friv | friv games | giochi | jeux

Katherine Hayden said...

I am very grateful to see your post. I would definitely keep a copy of this and would like to share this information in case study report writing service. it would help all to understand about the coding.

True Healing Self Healing said...

Very informative MySQL ... Please gives us more detail about MySQL

rio 2017 packages said...

I would love to stop by. But, I think it might have to wait until this summer. I did not know that Serlkay had ever expanded its size. I must say that a succesful family owned business in 2017 packages

2048 game said...

Wonderful blog! I found it while searching on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Many thanks.
2048 game | five nights at freddy's 4 | plants vs zombies | five nights at freddy's 3 | fireboy and watergirl | fireboy and watergirl 4||red ball | age of war

Blogger said...

Bluehost is ultimately one of the best web-hosting company for any hosting plans you require.

soclean said...

In starting you face many difficulties but now you should be consult with the PHP experts

Mohit Sharma said...

packers and movers in india@
packers and movers in delhi@
packers and movers in mumbai@
packers and movers in pune@
packers amd movers in gurgaon@

Jenny Thomas said...

That was a nice post to read.When the skill and knowledge work together, expect a master piece. Not everyone is gifted with the writing skill. But the continuous writing is a best technique to for improvement research paper writing service

Thomas pedro said...

Payday advances are wanted to delicate alleviation in emergency circumstances. For instance, auto repairs, close offs, past due bills, overdrafts, and wellbeing expenses is a motivating force to take out a payday advance. Payday Loans San-diego

bettycyoung said...

good to start seeing TELEVISION streaming on your COMPUTER. Mobdro App Gaming, Tech as well as several more nice.

Thomas pedro said...

A great deal of homeownership openings and lodging advantages are accessible to veterans who live in Texas. As a veteran, you have a privilege to know about these projects that can be exceptionally advantageous for you, particularly in case you're wanting to purchase a home in Weatherford land. Cash Advance