Solved

PHP self-test script   --  need suggestions

Posted on 2014-04-16
6
471 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 51

Expert Comment

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

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
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…

705 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

18 Experts available now in Live!

Get 1:1 Help Now