-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPHPSocks.php
94 lines (70 loc) · 2.07 KB
/
PHPSocks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
include "vendor/autoload.php";
date_default_timezone_set('Europe/Amsterdam');
if(!defined("DEBUG")){
$GLOBALS["sock"] = array();
}
register_shutdown_function(array("Socks", 'end'));
class Socks{
public static function info( $msg, $room = "default" ){
$result = Array();
$result['msg'] = $msg;
return self::call($result, $room);
}
public static function debug( $msg, $room = "default" ){
$result = Array();
$result['msg'] = $msg;
$result = self::addDetails( $result );
return self::call($result, $room);
}
public static function start( ){
$GLOBALS['sock']['start'] = microtime(true);
// return self::debug("The script start ".date("Y-m-d H:i:s") , "perfomance");
}
public static function end( ){
$GLOBALS['sock']['end'] = microtime(true);
$milliseconds = $GLOBALS['sock']['start'] - $GLOBALS['sock']['end'];
return self::debug("You script took {$milliseconds} to be executed", "perfomance");
}
public static function call($message, $room = "default"){
$msg = array("message" => $message, "room" => $room);
// $msg = json_encode($msg);
try {
$loop = new React\EventLoop\StreamSelectLoop();
$dnode = new DNode\DNode($loop);
$dnode->connect('localhost', 7070, function($remote, $connection) use ($msg) {
// Remote is a proxy object that provides us all methods
// from the server
$remote->debug($msg, function($n) use ($connection) {
if($n){
// echo "THE ERROR";
}
// echo "n = {$n}\n";
// Once we have the result we can close the connection
$connection->end();
});
});
$loop->run();
} catch (Exception $e){
echo "Debugger cannot send the request";
var_dump($e);
}
}
private static function addDetails( $result ){
$arr = array();
$arr['session'] = Array();
if ( isset($_SESSION) ){
$arr['session'] = $_SESSION;
}
$arr['server'] = Array();
if ( isset($_SERVER) ){
$arr['server'] = $_SERVER;
}
$arr['request'] = Array();
if ( isset($_REQUEST) ){
$arr['request'] = $_REQUEST;
}
$result = array_merge_recursive( $result, $arr );
return $result;
}
}