GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 2c70cc...15bbb1 )
by mike
02:51
created

blacklistmonitor.php ➔ main()   C

Complexity

Conditions 8
Paths 34

Size

Total Lines 34
Code Lines 21

Duplication

Lines 8
Ratio 23.53 %
Metric Value
cc 8
eloc 21
nc 34
nop 0
dl 8
loc 34
rs 5.3846
1
#!/bin/php
2
<?php
3
4
//prevent non cli access
5
if(php_sapi_name()!=='cli') exit();
6
7
$dir = dirname(dirname(__FILE__));
8
class_exists('Setup', false) or include($dir.'/classes/Setup.class.php');
9
class_exists('Utilities', false) or include($dir.'/classes/Utilities.class.php');
10
class_exists('_MySQL', false) or include($dir.'/classes/_MySQL.class.php');
11
class_exists('_MeasurePerformance', false) or include($dir.'/classes/_MeasurePerformance.class.php');
12
13
$options = getopt("p:i:");
14
$processType = isset($options['p']) ? $options['p'] : 'main';
15
$parentProcessId = isset($options['i']) ? (int)$options['i'] : 0;
16
17
18
switch ($processType) {
19
	case 'main';
20
		main();
21
		break;
22
	case 'monitorProcessWatch';
23
		monitorProcessWatch($parentProcessId);
24
		break;
25
	default:
26
		_Logging::appLog("Invalid process requested in main script");
27
		exit();
28
		break;
29
}
30
31
32
function main(){
33
	// start process watch
34
	$parentProcessId = getmypid();
35
	if($parentProcessId == false || $parentProcessId == 0) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $parentProcessId of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
36
		_Logging::appLog("Parent process couldnt get pid");
37
	}
38
39
	$userProcessId = 0;
40
	$monitorProcessesId = 0;
41
42
	$mysql = new _MySQL();
43
44
	// control
45
	while (true) {
46
		try{
47
			$mysql->connect(Setup::$connectionArray);
48
			if(!Utilities::is_process_running($userProcessId)){
49
				$userCheck = $mysql->runQueryReturnVar("select username from users where beenChecked = 0");
50 View Code Duplication
				if($userCheck!==false){
51
					$cmd = 'php '.dirname(__FILE__).'/userJob.php -i '.$parentProcessId;
52
					$userProcessId = Utilities::run_in_background($cmd);
53
				}
54
			}
55
		} catch (Exception $e) {
56
			_Logging::appLog($e->getMessage());
57
		}
58 View Code Duplication
		if(!Utilities::is_process_running($monitorProcessesId)){
59
			$cmd = 'php '.dirname(__FILE__).'/blacklistmonitor.php -p monitorProcessWatch -i '.$parentProcessId;
60
			$monitorProcessesId = Utilities::run_in_background($cmd);
61
		}
62
		sleep(15);//15 seconds
63
	}
64
65
}
66
67
function monitorProcessWatch($parentProcessId){
68
69
	$m = new _MeasurePerformance();
70
	$mysql = new _MySQL();
71
	$mysql->connect(Setup::$connectionArray);
72
73
	$parallelProcessesMonitors = Setup::$settings['max_monitor_processes'];
74
75
	$monitorProcesses = array();
76
	$processCountMonitors = 0;
0 ignored issues
show
Unused Code introduced by
$processCountMonitors is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
77
78
	$ipDomain = false;
79
80
	while (true) {
81
		// are we still running?
82
		if(!Utilities::is_process_running($parentProcessId)){
83
				_Logging::appLog("Parent Stopped - monitorStartWatch exited");
84
				exit();
85
		}
86
87
		$processCountMonitors = count($monitorProcesses);
88
89
		if ($processCountMonitors < $parallelProcessesMonitors){
90
				$ipDomain = Utilities::getNextMonitor($mysql);
91
				if ($ipDomain!==false) {
92
						// start it
93
						$cmd = 'php '.dirname(__FILE__).'/monitorJob.php -h '.escapeshellarg($ipDomain);
94
						$pid = Utilities::run_in_background($cmd);
95
						$m->work(1);
96
						$monitorProcesses[] = $pid;
97
				}
98
		}
99
100
		// was there any work?
101
		if($ipDomain===false){
102
				sleep(10);//10 seconds
103
		}else{
104
				usleep(10000);//ideal time 10ms
105
		}
106
107
		// delete finished processes
108
		for ($x = 0; $x < $processCountMonitors; $x++) {
109
				if(isset($monitorProcesses[$x])){
110
						if(!Utilities::is_process_running($monitorProcesses[$x])){
111
								unset($monitorProcesses[$x]);
112
						}
113
				}
114
		}
115
116
		// fix array index
117
		$monitorProcesses = array_values($monitorProcesses);
118
119
		$processCountMonitors = count($monitorProcesses);
120
121
		//randomly reset counter every now and then
122
		if(mt_rand(1,2000)==1){
123
			$m->endWork();
124
			_Logging::appLog("App Avg Hosts/sec: {$m->avgPerformance}\tMonitor Threads: $processCountMonitors/$parallelProcessesMonitors");
125
			$m = new _MeasurePerformance();
126
		}
127
128
	}
129
130
}
131