Exemplo n.º 1
0
function getRevisionAuthor($rev)
{
    $xmlLines = OS::executeAndReturnOutput("svn log -c {$rev} --xml");
    $xmlString = implode('', $xmlLines);
    $xml = simplexml_load_string($xmlString);
    return (string) $xml->logentry->author;
}
Exemplo n.º 2
0
require_once "../phplib/util.php";
ini_set('max_execution_time', '3600');
define('DB_QUERY', 'select * from Lexem where isLoc order by formNoAccent');
$locVersion = util_getRequestParameter('locVersion');
$newLocVersion = util_getRequestParameter('newLocVersion');
if ($newLocVersion) {
    if ($locVersion == $newLocVersion) {
        FlashMessage::add('Ați selectat aceeași versiune LOC de două ori');
        util_redirect('scrabble-loc');
    }
    $file1 = tempnam('/tmp', 'loc_diff_');
    $file2 = tempnam('/tmp', 'loc_diff_');
    writeLexems($locVersion, $file1);
    writeLexems($newLocVersion, $file2);
    $diff = OS::executeAndReturnOutput("diff {$file1} {$file2} || true");
    print "<pre>\n";
    foreach ($diff as $line) {
        if (StringUtil::startsWith($line, '< ')) {
            print sprintf("<span style=\"color: red\">%s: %s</span>\n", $locVersion, substr($line, 2));
        } else {
            if (StringUtil::startsWith($line, '> ')) {
                print sprintf("<span style=\"color: green\">%s: %s</span>\n", $newLocVersion, substr($line, 2));
            }
        }
    }
    print "</pre>\n";
    util_deleteFile($file1);
    util_deleteFile($file2);
    exit;
}
function isImage($fileName)
{
    // Check that the image exists
    $output = OS::executeAndReturnOutput("file \"{$fileName}\"");
    assert(count($output) == 1);
    if (strpos($output[0], 'JPEG image data') === false) {
        return IMG_NOT_JPEG;
    }
    $output = OS::executeAndReturnOutput("identify -verbose \"{$fileName}\" 2>&1 1>/dev/null");
    if (count($output)) {
        return IMG_CORRUPT;
        // because there are warnings
    }
    return IMG_NORMAL;
}
<?php

require_once "../phplib/util.php";
$PS_COMMAND = 'ps -eo user,pid,etime,args --no-headers --sort etime';
$APACHE_USER = '******';
$PHP_EXECUTABLE = '/usr/lib/cgi-bin/php5';
$TIME_LIMIT = 3600;
/*seconds */
log_scriptLog('Running killOrphanPhpProcesses.php.');
$output = OS::executeAndReturnOutput($PS_COMMAND);
foreach ($output as $line) {
    $parts = preg_split('/ +/', $line, 4);
    $runningTime = getRunningTime($parts[2]);
    if ($parts[0] == $APACHE_USER && $runningTime > $TIME_LIMIT && $parts[3] == $PHP_EXECUTABLE) {
        log_scriptLog("killing process {$parts[1]}");
        OS::executeAndAssert("kill -9 {$parts[1]}");
    }
}
log_scriptLog('killOrphanPhpProcesses.php done.');
/****************************************************************************/
// ps gives us the running time in [[DD-]hh:]mm:ss format.
function getRunningTime($string)
{
    $matches = array();
    preg_match("/^(?:(?:(\\d+)-)?(\\d+):)?(\\d+):(\\d+)\$/", $string, $matches);
    return $matches[1] * 86400 + $matches[2] * 3600 + $matches[3] * 60 + $matches[4];
}