本文整理汇总了PHP中CommonFunctions::fileexists方法的典型用法代码示例。如果您正苦于以下问题:PHP CommonFunctions::fileexists方法的具体用法?PHP CommonFunctions::fileexists怎么用?PHP CommonFunctions::fileexists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommonFunctions
的用法示例。
在下文中一共展示了CommonFunctions::fileexists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _temperature
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
if (PSI_OS == 'Linux') {
$hwpaths = glob("/sys/devices/platform/coretemp.*/", GLOB_NOSORT);
if (($totalh = count($hwpaths)) > 0) {
$buf = "";
for ($h = 0; $h < $totalh; $h++) {
$tempsensor = glob($hwpaths[$h] . "temp*_input", GLOB_NOSORT);
if (($total = count($tempsensor)) > 0) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($tempsensor[$i], $buf, 1, 4096, false) && trim($buf) != "") {
$dev = new SensorDevice();
$dev->setValue(trim($buf) / 1000);
$label = preg_replace("/_input\$/", "_label", $tempsensor[$i]);
$crit = preg_replace("/_input\$/", "_crit", $tempsensor[$i]);
$max = preg_replace("/_input\$/", "_max", $tempsensor[$i]);
$crit_alarm = preg_replace("/_input\$/", "_crit_alarm", $tempsensor[$i]);
if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && trim($buf) != "") {
$dev->setName(trim($buf));
} else {
$labelname = trim(preg_replace("/_input\$/", "", pathinfo($tempsensor[$i], PATHINFO_BASENAME)));
if ($labelname !== "") {
$dev->setName($labelname);
} else {
$dev->setName('unknown');
}
}
if (CommonFunctions::fileexists($crit) && CommonFunctions::rfts($crit, $buf, 1, 4096, false) && trim($buf) != "") {
$dev->setMax(trim($buf) / 1000);
if (CommonFunctions::fileexists($crit_alarm) && CommonFunctions::rfts($crit_alarm, $buf, 1, 4096, false) && trim($buf) === "1") {
$dev->setEvent("Critical Alarm");
}
} elseif (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && trim($buf) != "") {
$dev->setMax(trim($buf) / 1000);
}
$this->mbinfo->setMbTemp($dev);
}
}
}
}
}
} else {
$smp = 1;
CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp);
for ($i = 0; $i < $smp; $i++) {
$temp = 0;
if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.' . $i . '.temperature', $temp)) {
$temp = preg_replace('/C/', '', $temp);
$dev = new SensorDevice();
$dev->setName("CPU " . ($i + 1));
$dev->setValue($temp);
// $dev->setMax(70);
$this->mbinfo->setMbTemp($dev);
}
}
}
}
示例2: _distro
/**
* Distribution
*
* @return void
*/
private function _distro()
{
$this->sys->setDistribution("Linux");
$list = @parse_ini_file(APP_ROOT . "/data/distros.ini", true);
if (!$list) {
return;
}
// We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && strlen(trim($distro_info)) > 0) {
$distro_tmp = preg_split("/\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
foreach ($distro_tmp as $info) {
$info_tmp = preg_split('/:/', $info, 2);
if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && trim($distro_tmp[0]) != "" && isset($distro_tmp[1]) && !is_null($distro_tmp[1]) && trim($distro_tmp[1]) != "") {
$distro[trim($info_tmp[0])] = trim($info_tmp[1]);
}
}
if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) {
// Systems like StartOS
if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && trim($distro_tmp[0]) != "") {
$this->sys->setDistribution(trim($distro_tmp[0]));
if (preg_match('/^(\\S+)\\s*/', $distro_tmp[0], $id_buf) && isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
}
}
} else {
if (isset($distro['Description']) && preg_match('/^NAME=\\s*(.+)\\s*$/', $distro['Description'], $name_tmp)) {
$distro['Description'] = $name_tmp[1];
}
if (isset($distro['Description']) && $distro['Description'] != "n/a" && !isset($distro['Distributor ID'])) {
$this->sys->setDistribution($distro['Description']);
} elseif (isset($distro['Description']) && $distro['Description'] != "n/a" && isset($distro['Distributor ID']) && $distro['Distributor ID'] != "n/a" && $distro['Description'] != $distro['Distributor ID']) {
$this->sys->setDistribution($distro['Description']);
} elseif (isset($distro['Distributor ID']) && $distro['Distributor ID'] != "n/a") {
$this->sys->setDistribution($distro['Distributor ID']);
if (isset($distro['Release']) && $distro['Release'] != "n/a") {
$this->sys->setDistribution($this->sys->getDistribution() . " " . $distro['Release']);
}
if (isset($distro['Codename']) && $distro['Codename'] != "n/a") {
$this->sys->setDistribution($this->sys->getDistribution() . " (" . $distro['Codename'] . ")");
}
}
if (isset($distro['Distributor ID']) && $distro['Distributor ID'] != "n/a" && isset($list[$distro['Distributor ID']]['Image'])) {
$this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
}
}
} else {
/* default error handler */
if (function_exists('errorHandlerPsi')) {
restore_error_handler();
}
/* fatal errors only */
$old_err_rep = error_reporting();
error_reporting(E_ERROR);
// Fall back in case 'lsb_release' does not exist but exist /etc/lsb-release
if (CommonFunctions::fileexists($filename = "/etc/lsb-release") && CommonFunctions::rfts($filename, $buf, 0, 4096, false) && preg_match('/^DISTRIB_ID="?([^"\\n]+)"?/m', $buf, $id_buf)) {
if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\\n]+)"?/m', $buf, $desc_buf) && trim($desc_buf[1]) != trim($id_buf[1])) {
$this->sys->setDistribution(trim($desc_buf[1]));
} else {
if (isset($list[trim($id_buf[1])]['Name'])) {
$this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
} else {
$this->sys->setDistribution(trim($id_buf[1]));
}
if (preg_match('/^DISTRIB_RELEASE="?([^"\\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution() . " " . trim($vers_buf[1]));
}
if (preg_match('/^DISTRIB_CODENAME="?([^"\\n]+)"?/m', $buf, $vers_buf)) {
$this->sys->setDistribution($this->sys->getDistribution() . " (" . trim($vers_buf[1]) . ")");
}
}
if (isset($list[trim($id_buf[1])]['Image'])) {
$this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
}
} else {
// otherwise find files specific for distribution
foreach ($list as $section => $distribution) {
if (!isset($distribution['Files'])) {
continue;
} else {
foreach (preg_split("/;/", $distribution['Files'], -1, PREG_SPLIT_NO_EMPTY) as $filename) {
if (CommonFunctions::fileexists($filename)) {
$distro = $distribution;
if (isset($distribution['Mode']) && strtolower($distribution['Mode']) == "detection") {
$buf = "";
} elseif (isset($distribution['Mode']) && strtolower($distribution['Mode']) == "execute") {
if (!CommonFunctions::executeProgram($filename, '2>/dev/null', $buf, PSI_DEBUG)) {
$buf = "";
}
} else {
if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
$buf = "";
} elseif (isset($distribution['Mode']) && strtolower($distribution['Mode']) == "analyse") {
if (preg_match('/^(\\S+)\\s*/', preg_replace('/^Red\\s+/', 'Red', $buf), $id_buf) && isset($list[trim($id_buf[1])]['Image'])) {
$distro = $list[trim($id_buf[1])];
}
//.........这里部分代码省略.........
示例3: _current
/**
* get current information
*
* @return void
*/
private function _current($hwpath)
{
$sensor = glob($hwpath . "curr*_input", GLOB_NOSORT);
if (($total = count($sensor)) > 0) {
$buf = "";
for ($i = 0; $i < $total; $i++) {
if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && trim($buf) != "") {
$dev = new SensorDevice();
$dev->setValue(trim($buf) / 1000);
$label = preg_replace("/_input\$/", "_label", $sensor[$i]);
$alarm = preg_replace("/_input\$/", "_alarm", $sensor[$i]);
$max = preg_replace("/_input\$/", "_max", $sensor[$i]);
$min = preg_replace("/_input\$/", "_min", $sensor[$i]);
if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && trim($buf) != "") {
$dev->setName(trim($buf));
} else {
$labelname = trim(preg_replace("/_input\$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
if ($labelname !== "") {
$dev->setName($labelname);
} else {
$dev->setName('unknown');
}
}
if (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && trim($buf) != "") {
$dev->setMax(trim($buf) / 1000);
}
if (CommonFunctions::fileexists($min) && CommonFunctions::rfts($min, $buf, 1, 4096, false) && trim($buf) != "") {
$dev->setMin(trim($buf) / 1000);
}
if (CommonFunctions::fileexists($alarm) && CommonFunctions::rfts($alarm, $buf, 1, 4096, false) && trim($buf) === "1") {
$dev->setEvent("Alarm");
}
$this->mbinfo->setMbCurrent($dev);
}
}
}
}