Solved

PHP self-test script   --  need suggestions

Posted on 2014-04-16
6
477 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 108

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 53

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now