Issues (1358)

modules/WebSockets/index.php (2 issues)

1
<?php
2
/**
3
 * @package  WebSockets
4
 * @category modules
5
 * @author   Nazar Mokrynskyi <[email protected]>
6
 * @license  0BSD
7
 */
8
namespace cs\modules\WebSockets;
9
use
10
	cs\Config,
11
	cs\ExitException,
12
	cs\Page,
13
	cs\Request;
14
15
if (php_sapi_name() == 'cli') {
16
	Server::instance()->run(isset($_GET['address']) ? $_GET['address'] : null);
17
} else {
18
	Page::instance()->interface = false;
19
	$Config                     = Config::instance();
20
	$module_data                = $Config->module('WebSockets');
21
	$rc                         = Request::instance()->route;
22
	if ($module_data->security_key !== @$rc[0]) {
0 ignored issues
show
Bug Best Practice introduced by
The property security_key does not exist on cs\Config\Module_Properties. Since you implemented __get, consider adding a @property annotation.
Loading history...
23
		throw new ExitException(400);
24
	}
25
	if (is_server_running()) {
26
		echo 'Server already running';
27
		return;
28
	}
29
	if (is_exec_available()) {
30
		cross_platform_server_in_background();
31
		echo 'Server started';
32
	} else {
33
		set_time_limit(0);
34
		ignore_user_abort(1);
35
		if (!isset($rc[1])) {
36
			// Supervising for the case if server will go down
37
			while (true) {
38
				if (is_server_running()) {
39
					sleep(10);
40
					continue;
41
				}
42
				file_get_contents(
43
					$Config->base_url().'/WebSockets/'.$Config->module('WebSockets')->security_key.'/supervised',
0 ignored issues
show
Are you sure $Config->module('WebSockets')->security_key of type mixed|false can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
					$Config->base_url().'/WebSockets/'./** @scrutinizer ignore-type */ $Config->module('WebSockets')->security_key.'/supervised',
Loading history...
44
					null,
45
					stream_context_create(
46
						[
47
							'http' => [
48
								'timeout' => 0
49
							]
50
						]
51
					)
52
				);
53
			}
54
		} else {
55
			Server::instance()->run();
56
		}
57
	}
58
}
59