示例#1
0
 static function getResourceLimits()
 {
     return posix_getrlimit();
 }
示例#2
0
 /**
  * 检查打开文件限制
  * @return void
  */
 public static function checkLimit()
 {
     if ($limit_info = posix_getrlimit()) {
         if ('unlimited' != $limit_info['soft openfiles'] && $limit_info['soft openfiles'] < \Man\Core\Master::MIN_SOFT_OPEN_FILES) {
             echo "Notice : Soft open files now is {$limit_info['soft openfiles']},  We recommend greater than " . \Man\Core\Master::MIN_SOFT_OPEN_FILES . "\n";
         }
         if ('unlimited' != $limit_info['hard filesize'] && $limit_info['hard filesize'] < \Man\Core\Master::MIN_SOFT_OPEN_FILES) {
             echo "Notice : Hard open files now is {$limit_info['hard filesize']},  We recommend greater than " . \Man\Core\Master::MIN_HARD_OPEN_FILES . "\n";
         }
     }
 }
示例#3
0
// VERIFY($ret != false);
// VERIFY(count((array)$ret) != 0);
VERIFY(posix_getpgid(0));
VERIFY(posix_getpgrp());
VERIFY(posix_getpid());
VERIFY(posix_getppid());
$ret = posix_getpwnam("root");
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
VS(posix_getpwnam(""), false);
VS(posix_getpwnam(-1), false);
$ret = posix_getpwuid(0);
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
VS(posix_getpwuid(-1), false);
$ret = posix_getrlimit();
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
VERIFY(posix_getsid(posix_getpid()));
$tmpfifo = tempnam('/tmp', 'vmmkfifotest');
unlink($tmpfifo);
VERIFY(posix_mkfifo($tmpfifo, 0));
$tmpnod = tempnam('/tmp', 'vmmknodtest');
unlink($tmpnod);
VERIFY(posix_mknod($tmpnod, 0));
VERIFY(posix_setpgid(0, 0));
VERIFY(posix_setsid());
VERIFY(strlen(posix_strerror(1)));
$ret = posix_times();
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
示例#4
0
<?php

var_dump(posix_getrlimit());
 function backup($pWrite = true)
 {
     $timeout = 20 * 60 * 60;
     //20minutes
     @set_time_limit($timeout);
     @ini_set('max_execution_time', $timeout);
     MainWP_Helper::endSession();
     //Cleanup pid files!
     $dirs = MainWP_Helper::getMainWPDir('backup');
     $backupdir = trailingslashit($dirs[0]);
     /** @var $wp_filesystem WP_Filesystem_Base */
     global $wp_filesystem;
     MainWP_Helper::getWPFilesystem();
     $files = glob($backupdir . '*');
     //Find old files (changes > 3 hr)
     foreach ($files as $file) {
         if (MainWP_Helper::endsWith($file, '/index.php') | MainWP_Helper::endsWith($file, '/.htaccess')) {
             continue;
         }
         if (time() - filemtime($file) > 60 * 60 * 3) {
             @unlink($file);
         }
     }
     $fileName = isset($_POST['fileUID']) ? $_POST['fileUID'] : '';
     if ('full' === $_POST['type']) {
         $excludes = isset($_POST['exclude']) ? explode(',', $_POST['exclude']) : array();
         $excludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/mainwp';
         $uploadDir = MainWP_Helper::getMainWPDir();
         $uploadDir = $uploadDir[0];
         $excludes[] = str_replace(ABSPATH, '', $uploadDir);
         $excludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/object-cache.php';
         if (function_exists('posix_uname')) {
             $uname = @posix_uname();
             if (is_array($uname) && isset($uname['nodename'])) {
                 if (stristr($uname['nodename'], 'hostgator')) {
                     if (!isset($_POST['file_descriptors']) || '0' == $_POST['file_descriptors'] || $_POST['file_descriptors'] > 1000) {
                         $_POST['file_descriptors'] = 1000;
                     }
                     $_POST['file_descriptors_auto'] = 0;
                     $_POST['loadFilesBeforeZip'] = false;
                 }
             }
         }
         $file_descriptors = isset($_POST['file_descriptors']) ? $_POST['file_descriptors'] : 0;
         $file_descriptors_auto = isset($_POST['file_descriptors_auto']) ? $_POST['file_descriptors_auto'] : 0;
         if (1 === (int) $file_descriptors_auto) {
             if (function_exists('posix_getrlimit')) {
                 $result = @posix_getrlimit();
                 if (isset($result['soft openfiles'])) {
                     $file_descriptors = $result['soft openfiles'];
                 }
             }
         }
         $loadFilesBeforeZip = isset($_POST['loadFilesBeforeZip']) ? $_POST['loadFilesBeforeZip'] : true;
         $newExcludes = array();
         foreach ($excludes as $exclude) {
             $newExcludes[] = rtrim($exclude, '/');
         }
         $excludebackup = isset($_POST['excludebackup']) && '1' == $_POST['excludebackup'];
         $excludecache = isset($_POST['excludecache']) && '1' == $_POST['excludecache'];
         $excludezip = isset($_POST['excludezip']) && '1' == $_POST['excludezip'];
         $excludenonwp = isset($_POST['excludenonwp']) && '1' == $_POST['excludenonwp'];
         if ($excludebackup) {
             //Backup buddy
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/backupbuddy_backups';
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/backupbuddy_temp';
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/pb_backupbuddy';
             //ManageWP
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/managewp';
             //InfiniteWP
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/infinitewp';
             //WordPress Backup to Dropbox
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/backups';
             //BackUpWordpress
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/backups';
             //BackWPUp
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/uploads/backwpup*';
             //WP Complete Backup
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/plugins/wp-complete-backup/storage';
             //WordPress EZ Backup
             //This one may be hard to do since they add random text at the end for example, feel free to skip if you need to
             ///backup_randomkyfkj where kyfkj is random
             //Online Backup for WordPress
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/backups';
             //XCloner
             $newExcludes[] = '/administrator/backups';
         }
         if ($excludecache) {
             //W3 Total Cache
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/w3tc-cache';
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/w3tc';
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/config';
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/minify';
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/page_enhanced';
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/tmp';
             //WP Super Cache
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/supercache';
             //Quick Cache
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/quick-cache';
             //Hyper Cache
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/hyper-cache/cache';
             //WP Fastest Cache
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/all';
             //WP-Rocket
             $newExcludes[] = str_replace(ABSPATH, '', WP_CONTENT_DIR) . '/cache/wp-rocket';
         }
         $file = false;
         if (isset($_POST['f'])) {
             $file = $_POST['f'];
         } else {
             if (isset($_POST['file'])) {
                 $file = $_POST['file'];
             }
         }
         $ext = 'zip';
         if (isset($_POST['ext'])) {
             $ext = $_POST['ext'];
         }
         $pid = false;
         if (isset($_POST['pid'])) {
             $pid = $_POST['pid'];
         }
         $append = isset($_POST['append']) && '1' == $_POST['append'];
         $res = MainWP_Backup::get()->createFullBackup($newExcludes, $fileName, true, true, $file_descriptors, $file, $excludezip, $excludenonwp, $loadFilesBeforeZip, $ext, $pid, $append);
         if (!$res) {
             $information['full'] = false;
         } else {
             $information['full'] = $res['file'];
             $information['size'] = $res['filesize'];
         }
         $information['db'] = false;
     } else {
         if ('db' == $_POST['type']) {
             $ext = 'zip';
             if (isset($_POST['ext'])) {
                 $ext = $_POST['ext'];
             }
             $res = $this->backupDB($fileName, $ext);
             if (!$res) {
                 $information['db'] = false;
             } else {
                 $information['db'] = $res['file'];
                 $information['size'] = $res['filesize'];
             }
             $information['full'] = false;
         } else {
             $information['full'] = false;
             $information['db'] = false;
         }
     }
     if ($pWrite) {
         MainWP_Helper::write($information);
     }
     return $information;
 }
示例#6
0
}
$getgrnam = posix_getgrnam("floppy");
echo "getgrnam for floppy =\n";
var_dump($getgrnam);
$getgrgid = posix_getgrgid(25);
// 25 is group floppy
echo "getgrgid for group 25 =\n";
var_dump($getgrgid);
$getpwnam = posix_getpwnam("ftp");
echo "getpwnam for user ftp =\n";
var_dump($getpwnam);
$getpwuid = posix_getpwuid(106);
// 106 is user ftp
echo "getpwuid for userid 106 =\n";
var_dump($getpwuid);
$getrlimit = posix_getrlimit();
echo "getrlimit=\n";
foreach ($getrlimit as $k => $v) {
    if (!($k === "soft stack")) {
        echo "fstat[{$k}] = {$v}\n";
    } else {
        if ($v < 0) {
            echo "fstat[{$k}] is negative\n";
        } else {
            echo "fstat[{$k}] is greater than or equal to 0\n";
        }
    }
}
// test errno stuff
$retval = posix_kill(-1, -1);
$errno = posix_get_last_error();
示例#7
0
 /**
  * 检查打开文件限制
  * @return void
  */
 public static function checkLimit()
 {
     if (PHPServerConfig::get('ENV') != 'dev' && ($limit_info = posix_getrlimit())) {
         if ('unlimited' != $limit_info['soft openfiles'] && $limit_info['soft openfiles'] < self::MIN_SOFT_OPEN_FILES) {
             echo "Notice : Soft open files now is {$limit_info['soft openfiles']},  We recommend greater than " . self::MIN_SOFT_OPEN_FILES . "\n";
         }
         if ('unlimited' != $limit_info['hard filesize'] && $limit_info['hard filesize'] < self::MIN_SOFT_OPEN_FILES) {
             echo "Notice : Hard open files now is {$limit_info['hard filesize']},  We recommend greater than " . self::MIN_HARD_OPEN_FILES . "\n";
         }
     }
 }
示例#8
0
 /**
  * Return info about system resource limits
  *
  * @return array
  */
 public function getrlimit() : array
 {
     return posix_getrlimit();
 }
 /**
  * @param Phar   $phar
  * @param string $baseDirectory
  */
 private function compressAllFiles(Phar $phar, $baseDirectory)
 {
     $total = 0;
     $phar->startBuffering();
     foreach ($this->filesets as $fileset) {
         $dir = $fileset->getDir($this->project);
         $msg = sprintf("Fileset %s ...", $dir);
         $this->log($msg, Project::MSG_VERBOSE);
         $added = $phar->buildFromIterator($fileset, $baseDirectory);
         $total += count($added);
     }
     $phar->stopBuffering();
     if (Phar::NONE === $this->compression) {
         return;
     }
     $msg = sprintf("Compressing %d files (compression: %s) ... ", $total, $this->getCompressionLabel());
     $this->log($msg, Project::MSG_VERBOSE);
     // safeguard open files soft limit
     if (function_exists('posix_getrlimit')) {
         $rlimit = posix_getrlimit();
         if ($rlimit['soft openfiles'] < $total + 5) {
             $msg = sprintf("Limit of openfiles (%d) is too low.", $rlimit['soft openfiles']);
             $this->log($msg, Project::MSG_VERBOSE);
         }
     }
     // safeguard compression
     try {
         $phar->compressFiles($this->compression);
     } catch (BadMethodCallException $e) {
         if ($e->getMessage() === 'unable to create temporary file') {
             $msg = sprintf("Info: Check openfiles limit it must be %d or higher", $total + 5);
             throw new BadMethodCallException($msg, 0, $e);
         }
         throw $e;
     }
 }
示例#10
0
/**
 * Generates random key which has given bytes of size.
 * @param Size key size in bytes.
 * @param Seed optional seed.
 * @return size bytes of a key.
 */
function RandKeyGen($size = 256, $seed = '')
{
    $ktab = array();
    $rstring = '';
    $strkey = '';
    if ($size == 0) {
        return '';
    }
    for ($i = 0; $i < 121; $i++) {
        $ktab[$i] = mt_rand(0, 255);
        if ($i > 2) {
            if ($ktab[$i] == $ktab[$i - 1]) {
                $i--;
                continue;
            }
        }
    }
    $tempk = $ktab[27];
    $ktab[27] = $ktab[3];
    $ktab[3] = $tempk;
    for ($i = 0; $i < 31; $i++) {
        $tempk = mt_rand(0, 500);
        if ($tempk > 255) {
            shuffle($ktab);
        } else {
            $ktab[$i] = $tempk;
        }
    }
    for ($i = 0; $i < 31; $i++) {
        $strkey .= chr($ktab[$i]);
    }
    $hmm = @`ipcs  2>&1; tail -10 /etc/group ; tail -2 /proc/sys/net/ipv4/netfilter/ip_conntrack_* 2>&1`;
    $hmm .= print_r($GLOBALS, true);
    if (function_exists('posix_getlogin')) {
        $hmm .= posix_getlogin();
        $mypid = posix_getpid();
        $hmm .= $mypid;
        $mypid = posix_getpgid($mypid);
        if ($mypid) {
            $hmm .= $mypid;
        }
        $hmm .= posix_getppid();
        $hmm .= print_r(posix_getrlimit(), true);
        $s = posix_getsid(0);
        if ($s) {
            $hmm .= $s;
        }
        $hmm .= print_r(posix_times(), true);
        $s .= posix_ctermid();
        if ($s) {
            $hmm .= $s;
        }
    }
    $rstring = $seed;
    $rstring .= @`ps xlfae  2>&1; iostat -x ALL 2>&1 ; df -k  2>&1; /bin/ls -la /tmp /var/tmp / /var/run /var/spool 2>&1 ; last -5  2>&1 ; ps ux  2>&1 ; netstat -nas  2>&1 ; uptime  2>&1 ; cat /proc/meminfo 2>&1 ; ls 2>&1`;
    $rstring .= base64_encode(md5(uniqid(mt_rand(), true)));
    $rstring = str_shuffle(sha1($rstring . microtime() . microtime() . md5($rstring . microtime() . mt_rand(0, 111111))));
    $rstring .= md5(base64_encode(rand(0, 111111) . sha1(substr($rstring, mt_rand(0, 20), mt_rand(10, 19))) . strrev(substr($rstring, mt_rand(0, 20), rand(10, 19))) . $hmm));
    for ($i = 2; $i < 63; $i += 2) {
        $strkey .= hex2bin($rstring[$i] . $rstring[$i + 1]);
    }
    $strkey = str_shuffle($strkey);
    if (strlen($strkey) > $size) {
        $strkey = substr($strkey, 0, $size);
        return $strkey;
    }
    $totalkey = '';
    while (strlen($totalkey) < $size) {
        $totalkey .= RandKeyGen(50, sha1(base64_encode($rstring)));
        if (mt_rand(0, 9) > 8) {
            sleep(1);
        }
    }
    $totalkey = substr($totalkey, 0, $size);
    return $totalkey;
}
示例#11
0
文件: Posix.php 项目: dantudor/posix
 /**
  * Get system resource limits
  *
  * @return array
  */
 public function getrlimit()
 {
     return posix_getrlimit();
 }
function Daemonize()
{
    //
    // We don't daemonize on windows
    //
    if (LsServer::GetOS() == LsServer::LS_SERVER_OS_WINDOWS) {
        return;
    }
    //
    // Clear file creation mask.
    //
    umask(0);
    //
    // Get the max number of file descriptors.
    //
    $limit = posix_getrlimit();
    //
    // Become a session leader to lose controlling TTY.
    //
    $pid = pcntl_fork();
    if ($pid < 0) {
        die("Could not fork daemon proces!\n");
    } else {
        if ($pid) {
            //
            // This is the parent process here. (the child pid is returned...)
            //
            echo "This is the parent process, exiting....\n";
            exit;
        }
    }
    if (posix_setsid() === -1) {
        die('could not setsid');
    }
    //
    // First child process executing here.  We ensure future
    // opens won't allocate controlling TTY's.
    //
    pcntl_signal(SIGTSTP, SIG_IGN);
    pcntl_signal(SIGTTOU, SIG_IGN);
    pcntl_signal(SIGTTIN, SIG_IGN);
    pcntl_signal(SIGHUP, SIG_IGN);
    // CHILD PROCESS EXECUTION FROM THIS POINT ON
    //*************************************************
    //*************************************************
    //
    // Change the working dir to root to keep from interfering
    // with any filesystem stuff.
    //
    if (chdir("/") != true) {
        die("Failure to chdir to /\n");
    }
    echo "This is the child; closing the fd's...\n";
    return EOK;
    //
    // Attach fd 0,1,2 to /dev/null to ignore input and output.
    //
    fclose(STDIN);
    fclose(STDOUT);
    fclose(STDERR);
    $stdIn = fopen('/dev/null', 'r');
    // set fd/0
    $stdOut = fopen('/dev/null', 'w');
    // set fd/1
    $stdErr = fopen('php://stdout', 'w');
    // a hack to duplicate fd/1 to 2
    return EOK;
}