phplibrary/src/Process.php

44 lines
1.1 KiB
PHP

<?php
namespace ctiso;
if (!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter = ",", $enclosure = '"', $escape = "\\") {
$fiveMBs = 1024;
$fp = fopen("php://temp/maxmemory:$fiveMBs", 'r+');
$data = '';
if (is_resource($fp)) {
fputs($fp, $input);
rewind($fp);
$data = fgetcsv($fp, 1000, $delimiter, $enclosure);
fclose($fp);
}
return $data;
}
}
function process_exists($pid) {
if (PHP_OS == 'WINNT') {
$processes = explode("\n", shell_exec("tasklist.exe /NH /FO CSV"));
foreach($processes as $process) {
if ($process != "") {
$csv = str_getcsv($process);
if ($pid == $csv[1]) return true;
}
}
return false;
} else {
return file_exists("/proc/$pid");
}
}
function create_single_proces($fpid, $fn) {
if (file_exists($fpid)) {
print_r(realpath($fpid));
if (process_exists(file_get_contents($fpid))) {
return 1;
}
}
call_user_func($fn);
return 0;
}