本文整理汇总了PHP中unix::PIDOF_BY_PORT方法的典型用法代码示例。如果您正苦于以下问题:PHP unix::PIDOF_BY_PORT方法的具体用法?PHP unix::PIDOF_BY_PORT怎么用?PHP unix::PIDOF_BY_PORT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unix
的用法示例。
在下文中一共展示了unix::PIDOF_BY_PORT方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: killbyports
function killbyports()
{
$sock = new sockets();
$unix = new unix();
$kill = $unix->find_program("kill");
$ufdbguardConfig = unserialize(base64_decode($sock->GET_INFO("ufdbguardConfig")));
if (!isset($datas["listen_addr"])) {
$datas["listen_addr"] = "127.0.0.1";
}
if (!isset($datas["listen_port"])) {
$datas["listen_port"] = "3977";
}
if (!isset($datas["tcpsockets"])) {
$datas["tcpsockets"] = 0;
}
if ($datas["listen_addr"] == null) {
$datas["listen_addr"] = "127.0.0.1";
}
if (!is_numeric($datas["listen_port"])) {
$datas["listen_port"] = "3977";
}
if ($datas["tcpsockets"] == 0) {
return 1;
}
$PIDS = $unix->PIDOF_BY_PORT($datas["listen_port"]);
if (count($PIDS) == 0) {
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} 0 PID listens {$datas["listen_port"]}...\n";
}
return;
}
while (list($pid, $b) = each($PIDS)) {
if ($unix->process_exists($pid)) {
$cmdline = @file_get_contents("/proc/{$pid}/cmdline");
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} killing PID {$pid} that listens {$datas["listen_port"]} TCP port\n";
}
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmdline}\n";
}
unix_system_kill_force($pid);
}
}
}
示例2: killbyports
function killbyports()
{
$sock = new sockets();
$unix = new unix();
$kill = $unix->find_program("kill");
$SyncThingPort = intval($sock->GET_INFO("SyncThingPort"));
if ($SyncThingPort == 0) {
$SyncThingPort = 8000;
}
$PIDS = $unix->PIDOF_BY_PORT($SyncThingPort);
if (count($PIDS) == 0) {
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} 0 PID listens {$SyncThingPort}...\n";
}
return;
}
while (list($pid, $b) = each($PIDS)) {
if ($unix->process_exists($pid)) {
$cmdline = @file_get_contents("/proc/{$pid}/cmdline");
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} killing PID {$pid} that listens {$SyncThingPort}} TCP port\n";
}
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmdline}\n";
}
unix_system_kill_force($pid);
}
}
}
示例3: fuser_port
function fuser_port()
{
$unix = new unix();
$kill = $unix->find_program("kill");
build_progress_restart("{checking} TCP:5432", 66);
$PIDS = $unix->PIDOF_BY_PORT("5432");
if (count($PIDS) == 0) {
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} 0 PID listens 5432...\n";
}
return;
}
while (list($pid, $b) = each($PIDS)) {
if ($unix->process_exists($pid)) {
build_progress_restart("{killing} {$pid} : 5432", 67);
$cmdline = @file_get_contents("/proc/{$pid}/cmdline");
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} killing PID {$pid} that listens 53 UDP port\n";
}
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmdline}\n";
}
unix_system_kill_force($pid);
}
}
}
示例4: fuser_port
function fuser_port($port)
{
$unix = new unix();
$kill = $unix->find_program("kill");
$PIDS = $unix->PIDOF_BY_PORT($port);
if (count($PIDS) == 0) {
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} 0 PID listens {$port}...\n";
}
return;
}
while (list($pid, $b) = each($PIDS)) {
if ($unix->process_exists($pid)) {
if ($GLOBALS["OUTPUT"]) {
echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} killing PID {$pid} that listens {$port}\n";
}
unix_system_kill_force($pid);
}
}
}
示例5: start_squid
//.........这里部分代码省略.........
start_prepare();
$pid = SQUID_PID();
if ($GLOBALS["CRASHED"]) {
for ($i = 0; $i < 10; $i++) {
sleep(1);
$pid = SQUID_PID();
if ($unix->process_exists($pid)) {
continue;
}
break;
}
squid_admin_mysql(2, "No need to start Proxy service after a crash", "It seems the watchdog detect a crash but after 10s the proxy still running\nOperation is aborted", __FILE__, __LINE__);
return;
}
if ($unix->process_exists($pid)) {
$time = $unix->PROCCESS_TIME_MIN($pid);
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " Proxy service already running pid {$pid} since {$time}mn\n";
}
system_admin_events("Squid seems to already running pid {$pid} since {$time}mn", __FUNCTION__, __FILE__, __LINE__, "proxy");
return;
}
$unix->TCP_TUNE_SQUID_DEFAULT();
$t1 = time();
SendLogs("Checking caches...");
$cacheBooster = new squidbooster();
$cacheBooster->cache_booster();
CheckStoreDirs(true);
SendLogs("Checking caches done...");
SendLogs("Checking Ports...");
$array = CheckAllports();
SendLogs("Checking " . count($array) . " ports");
while (list($port, $ligne) = each($array)) {
$portZ = $unix->PIDOF_BY_PORT($port);
SendLogs("Checking port {$port} - " . count($portZ) . " process(es)");
if (count($portZ) > 0) {
while (list($pid, $ligne) = each($portZ)) {
SendLogs("Checking port {$port} - killing pid {$pid}");
shell_exec("kill -9 {$pid} >/dev/null 2>&1");
}
}
}
SendLogs("Starting squid {$squidbin}....");
$echo = $unix->find_program("echo");
$size = round(@filesize("/var/log/squid/cache.log") / 1024, 2) / 1024;
if ($size > 10) {
@copy("/var/log/squid/cache.log", "/var/log/squid/cache.log." . time());
shell_exec("{$echo} \" \"> /var/log/squid/cache.log 2>&1");
}
@chmod($squidbin, 0755);
@chmod("/var/log/squid", 0755);
if (is_link("/var/log/squid")) {
@chmod(readlink("/var/log/squid"), 0755);
}
squid_admin_mysql(1, "Starting Squid-cache service {$suffix}", @implode("\n", $GLOBALS["LOGS"]), __FILE__, __LINE__);
exec("{$squidbin} -f /etc/squid3/squid.conf 2>&1", $GLOBALS["LOGS"]);
$PRC = 40;
$MAXPRC = 60;
$AB = 0;
for ($i = 0; $i < 10; $i++) {
$PRC++;
if ($PRC > $MAXPRC - 1) {
$PRC = $MAXPRC - 1;
}
build_progress_restart("{starting_service}", $PRC);
$pid = SQUID_PID();
示例6: start
function start($aspid = false)
{
$unix = new unix();
$sock = new sockets();
if (!$aspid) {
$pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
$pid = $unix->get_pid_from_file($pidfile);
if ($unix->process_exists($pid, basename(__FILE__))) {
$time = $unix->PROCCESS_TIME_MIN($pid);
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
}
return;
}
@file_put_contents($pidfile, getmypid());
}
$ROUNDCUBE_MAIN_FOLDER = ROUNDCUBE_MAIN_FOLDER();
if (!is_dir(ROUNDCUBE_MAIN_FOLDER())) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n";
}
return;
}
$RoundCubeHTTPEngineEnabled = intval($sock->GET_INFO("RoundCubeHTTPEngineEnabled"));
$pid = LIGHTTPD_PID();
if ($RoundCubeHTTPEngineEnabled == 0) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} disabled (RoundCubeHTTPEngineEnabled)..\n";
}
if ($unix->process_exists($pid)) {
stop(true);
}
return;
}
if ($unix->process_exists($pid)) {
$timepid = $unix->PROCCESS_TIME_MIN($pid);
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$GLOBALS["SERVICE_NAME"]} already started {$pid} since {$timepid}Mn...\n";
}
return;
}
$nohup = $unix->find_program("nohup");
$php5 = $unix->LOCATE_PHP5_BIN();
$apache2ctl = $unix->LOCATE_APACHE_CTL();
$LIGHTTPD_CONF_PATH = LIGHTTPD_CONF_PATH();
$RoundCubeHTTPSPort = intval($sock->GET_INFO("RoundCubeHTTPSPort"));
$RoundCubeHTTPPort = intval($sock->GET_INFO("RoundCubeHTTPPort"));
$RoundCubeUseSSL = intval($sock->GET_INFO("RoundCubeUseSSL"));
if ($RoundCubeHTTPSPort == 0) {
$RoundCubeHTTPSPort = 449;
}
if ($RoundCubeHTTPPort == 0) {
$RoundCubeHTTPPort = 8888;
}
if (!is_file("/opt/artica/ssl/certs/lighttpd.pem")) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating SSL certificate..\n";
}
exec("/usr/share/artica-postfix/bin/artica-install -lighttpd-cert 2>&1", $results);
while (list($num, $line) = each($results)) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$line}\n";
}
}
}
apache_config();
if ($RoundCubeUseSSL == 1) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Get PID from PORT HTTPS/TCP:{$RoundCubeHTTPSPort}\n";
}
$pids = $unix->PIDOF_BY_PORT($RoundCubeHTTPSPort);
if (count($pids) > 0) {
while (list($pid, $line) = each($pids)) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} kill PID {$pid} that listens {$RoundCubeHTTPSPort}\n";
}
$unix->KILL_PROCESS($pid, 9);
}
}
}
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Get PID from PORT HTTP/TCP:{$RoundCubeHTTPPort}\n";
}
$pids = $unix->PIDOF_BY_PORT($RoundCubeHTTPPort);
if (count($pids) > 0) {
while (list($pid, $line) = each($pids)) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} kill PID {$pid} that listens {$RoundCubeHTTPPort}\n";
}
$unix->KILL_PROCESS($pid, 9);
}
}
$cmd = "{$apache2ctl} -f {$LIGHTTPD_CONF_PATH} -k start";
if ($GLOBALS["VERBOSE"]) {
echo "{$cmd}\n";
}
shell_exec($cmd);
for ($i = 0; $i < 6; $i++) {
$pid = LIGHTTPD_PID();
if ($unix->process_exists($pid)) {
//.........这里部分代码省略.........
示例7: start_squid
//.........这里部分代码省略.........
build_progress_start("Preparing proxy service", 50);
start_prepare();
$squid_checks = new squid_checks();
$squid_checks->squid_parse();
build_progress_start("{starting_proxy_service}", 60);
$pid = SQUID_PID();
if ($GLOBALS["CRASHED"]) {
for ($i = 0; $i < 10; $i++) {
sleep(1);
$pid = SQUID_PID();
if ($unix->process_exists($pid)) {
continue;
}
break;
}
squid_admin_mysql(2, "No need to start Proxy service after a crash", "It seems the watchdog detect a crash but after 10s the proxy still running\nOperation is aborted", __FILE__, __LINE__);
return;
}
build_progress_start("Tuning network", 70);
$unix->TCP_TUNE_SQUID_DEFAULT();
$t1 = time();
build_progress_start("Checking caches", 71);
SendLogs("Checking caches...");
$cacheBooster = new squidbooster();
$cacheBooster->cache_booster();
build_progress_start("Checking caches", 73);
CheckStoreDirs(true);
SendLogs("Checking caches done...");
build_progress_start("Checking Ports", 75);
SendLogs("Checking Ports...");
$array = CheckAllports();
SendLogs("Checking " . count($array) . " ports");
while (list($port, $ligne) = each($array)) {
$portZ = $unix->PIDOF_BY_PORT($port);
SendLogs("Checking port {$port} - " . count($portZ) . " process(es)");
if (count($portZ) > 0) {
while (list($pid, $ligne) = each($portZ)) {
SendLogs("Checking port {$port} - killing pid {$pid}");
shell_exec("kill -9 {$pid} >/dev/null 2>&1");
}
}
}
build_progress_start("Checking SHM", 75);
system("{$php} /usr/share/artica-postfix/exec.squid.smp.php");
SendLogs("Starting squid {$squidbin}....");
$echo = $unix->find_program("echo");
$size = round(@filesize("/var/log/squid/cache.log") / 1024, 2) / 1024;
if ($size > 50) {
squid_admin_mysql(2, "Cleaning cache.log {$size}MB", null, __FILE__, __LINE__);
@copy("/var/log/squid/cache.log", "/var/log/squid/cache.log." . time());
shell_exec("{$echo} \" \"> /var/log/squid/cache.log 2>&1");
}
@chmod($squidbin, 0755);
@chmod("/var/log/squid", 0755);
if (is_link("/var/log/squid")) {
@chmod(readlink("/var/log/squid"), 0755);
}
squid_admin_mysql(1, "Starting Squid-cache service {$suffix}", @implode("\n", $GLOBALS["LOGS"]), __FILE__, __LINE__);
build_progress_start("Remove SystemV5 Memory", 80);
kill_shm();
CHECK_WIFIDOG_IPTABLES_RULES();
$PIDFILE = $unix->LOCATE_SQUID_PID();
$f = array();
$f[] = "#! /bin/sh";
$f[] = ". /lib/lsb/init-functions";
$f[] = "PATH=/bin:/usr/bin:/sbin:/usr/sbin";
示例8: start
function start($aspid = false)
{
$unix = new unix();
$sock = new sockets();
$Masterbin = $unix->find_program("rdpproxy");
if (!is_file($Masterbin)) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, rdpproxy not installed\n";
}
return;
}
if (!$aspid) {
$pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
$pid = $unix->get_pid_from_file($pidfile);
if ($unix->process_exists($pid, basename(__FILE__))) {
$time = $unix->PROCCESS_TIME_MIN($pid);
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
}
return;
}
@file_put_contents($pidfile, getmypid());
}
$pid = PID_NUM();
if ($unix->process_exists($pid)) {
$timepid = $unix->PROCCESS_TIME_MIN($pid);
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
}
return;
}
$EnableRDPProxy = $sock->GET_INFO("EnableRDPProxy");
if (!is_numeric($EnableRDPProxy)) {
$EnableRDPProxy = 0;
}
if ($EnableRDPProxy == 0) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableRDPProxy)\n";
}
return;
}
$nohup = $unix->find_program("nohup");
$kill = $unix->find_program("kill");
$RDPProxyPort = $sock->GET_INFO("RDPProxyPort");
if (!is_numeric($RDPProxyPort)) {
$RDPProxyPort = 3389;
}
$PIDS = $unix->PIDOF_BY_PORT($RDPProxyPort);
if (count($PIDS) == 0) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} 0 PID listens {$RDPProxyPort}...\n";
}
}
if (count($PIDS) > 0) {
while (list($pid, $b) = each($PIDS)) {
if ($unix->process_exists($pid)) {
$cmdline = @file_get_contents("/proc/{$pid}/cmdline");
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} killing PID {$pid} that listens {$RDPProxyPort} TCP port\n";
}
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Process: `{$cmdline}`\n";
}
unix_system_kill_force($pid);
}
}
}
@mkdir('/etc/rdpproxy/cert/rdp', 0755, true);
@mkdir("/var/rdpproxy/recorded", 0755, true);
@mkdir("/var/run/redemption", 0755, true);
@mkdir("/tmp/rdpproxy", 0755, true);
@mkdir("/home/rdpproxy/recorded", 0755, true);
foreach (glob("/usr/share/artica-postfix/img/rdpproxy/*") as $filename) {
if ($GLOBALS["VERBOSE"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} \"" . basename($filename) . "\"\n";
}
@copy($filename, "/usr/local/share/rdpproxy/" . basename($filename));
}
if (is_file("/var/run/redemption/rdpproxy.pid")) {
@unlink("/var/run/redemption/rdpproxy.pid");
}
$VERSION = VERSION();
$cmd = "{$nohup} {$Masterbin} >/dev/null 2>&1 &";
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service v.{$VERSION}\n";
}
shell_exec($cmd);
for ($i = 1; $i < 5; $i++) {
if ($GLOBALS["OUTPUT"]) {
echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
}
sleep(1);
$pid = PID_NUM();
if ($unix->process_exists($pid)) {
break;
}
}
$pid = PID_NUM();
if ($unix->process_exists($pid)) {
if ($GLOBALS["OUTPUT"]) {
//.........这里部分代码省略.........