Esempio n. 1
0
/**
 * Return the used process memory, in bytes.
 * Enable the section which will work for you. They are very slow.
 * Special quirks for Windows: Requires cygwin.
 */
function getMemoryUsage()
{
    //if (!(DEBUG & _DEBUG_VERBOSE)) return;
    if (function_exists('memory_get_usage') and memory_get_usage()) {
        return memory_get_usage();
    } elseif (function_exists('getrusage') and $u = @getrusage() and !empty($u['ru_maxrss'])) {
        $mem = $u['ru_maxrss'];
    } elseif (substr(PHP_OS, 0, 3) == 'WIN') {
        // may require a newer cygwin
        // what we want is the process memory only: apache or php (if CGI)
        $pid = getmypid();
        $memstr = '';
        // win32_ps_stat_proc, win32_ps_stat_mem
        if (function_exists('win32_ps_list_procs')) {
            $info = win32_ps_stat_proc($pid);
            $memstr = $info['mem']['working_set_size'];
        } elseif (0) {
            // This works only if it's a cygwin process (apache or php).
            // Requires a newer cygwin
            $memstr = exec("cat /proc/{$pid}/statm |cut -f1");
            // if it's native windows use something like this:
            //   (requires pslist from sysinternals.com, grep, sed and perl)
            //$memstr = exec("pslist $pid|grep -A1 Mem|sed 1d|perl -ane\"print \$"."F[5]\"");
        }
        return (int) trim($memstr);
    } elseif (1) {
        $pid = getmypid();
        //%MEM: Percentage of total memory in use by this process
        //VSZ: Total virtual memory size, in 1K blocks.
        //RSS: Real Set Size, the actual amount of physical memory allocated to this process.
        //CPU time used by process since it started.
        //echo "%",`ps -o%mem,vsz,rss,time -p $pid|sed 1d`,"\n";
        $memstr = exec("ps -orss -p {$pid}|sed 1d");
        return (int) trim($memstr);
    }
}
Esempio n. 2
0
 function processExists($pn_proc_id)
 {
     if (!$this->canDetectProcesses()) {
         return null;
     }
     switch (caGetOSFamily()) {
         case OS_WIN32:
             $va_proc_info = win32_ps_stat_proc($pn_proc_id);
             return is_array($va_proc_info);
             break;
         default:
             return posix_kill($pn_proc_id, 0) ? true : false;
             break;
     }
 }