Solved

PHP self-test script   --  need suggestions

Posted on 2014-04-16
6
481 Views
Last Modified: 2014-04-21
A client has an account on a vendor's server.  We have no control over system updates/parameters.
About once a week something will happen that breaks some facet of PHP.
the most common is suhosin either gets protected or uninstalled.
example error:

[16-Apr-2014 09:15:01] PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20060613/suhosin.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20060613/suhosin.so: cannot open shared object file: No such file or directory in Unknown on line 0

Please offer experience/advice/suggestions for a script  that can be run in an (hourly) cron job that checks basic PHP health (including suhosin)  and if there's a problem
emails the error to us.

thanks
0
Comment
Question by:willsherwood
6 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 475 total points
ID: 40004130
Good grief!  Get a new hosting company!  That's a technically incompetent installation, and if the hosting company cannot fix it, they don't know what they are doing and that is dangerous for your work.  You probably do not want Suhosin in any case.

If you want to look for the error_log file, this script will do the job.  You may want to modify it to send an email, text or tweet.  It will scan all of the directories in the tree and show you the error_log contents.  Install it in the web root and run it from the browser to see what it creates.

<?php // find_error_log.php
error_reporting(E_ALL);
ob_start();

// PUT THIS SCRIPT IN THE WEB ROOT DIRECTORY
$path = realpath(getcwd());
$plen = strlen($path);

// THE ERROR LOG FILE NAME
$signal = strrev('error_log');


// IF THERE IS A POST-METHOD REQUEST TO DELETE THE ERROR LOG
if (!empty($_POST['log']))
{
    // MAKE SURE WE ONLY UNLINK THE ERROR LOG FILE
    $test = strrev($_POST['log']);
    if (strpos($test, $signal) === 0)
    {
        unlink($path . $_POST['log']);
        echo '<h3>' . $_POST['log'] . ' Discarded</h3>';
    }
}


// SEE http://php.net/manual/en/class.recursivedirectoryiterator.php#85805
$objs = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);

// UNFORTUNATELY THIS DOES NOT WORK AT PHP 5.4
// var_dump($objs);

// ITERATE OVER THE OBJECTS
foreach($objs as $name => $obj)
{
    // PROCESS THE ERROR LOG ONLY
    $test = strrev($name);
    if (strpos($test, $signal) === 0)
    {
        $name = substr($name, $plen);
        $form = <<<EOD
<form method="post" style="margin:0; padding:0; display:inline;!important">
<b>$name</b>
<input type="submit" value="Discard?" />
<input type="hidden" name="log" value="$name" />
</form>
EOD;
        echo $form;

        // SHOW THE CONTENTS OF THE ERROR LOG
        echo '<pre>';
        print_r(file_get_contents($path . $name));
        echo "</pre>" . PHP_EOL;
    }
}

$out = ob_get_contents();
if (empty($out)) echo '<h3>Good News! No error_log found.</h3>';

Open in new window

HTH, ~Ray
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 40004274
Move to another hosting company.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 25 total points
ID: 40004640
I was getting that on Penguin / Chihost for a long time because suhosin doesn't run with PHP 5.4 but apparently they weren't changing the 'php.ini' on that server.  I just checked and that error has finally stopped.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 475 total points
ID: 40004716
I got those on ChiHost, too.  It didn't seem to affect my scripts - it just filled up the error logs.  When I told them about it, they fixed it and the problem went away.
0
 

Author Closing Comment

by:willsherwood
ID: 40012895
thanks all!
(unfortunately it's not my choice regarding the provider for this client)
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40013020
At least let your client know the consensus from the Experts!

Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question