?
Solved

PHP self-test script   --  need suggestions

Posted on 2014-04-16
6
Medium Priority
?
520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1900 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 58

Expert Comment

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

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 100 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1900 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 111

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
Suggested Courses

741 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