|
1
|
|
|
<?php |
|
2
|
|
|
namespace PHPDaemon\Examples; |
|
3
|
|
|
|
|
4
|
|
|
use PHPDaemon\Core\Daemon;use PHPDaemon\HTTPRequest\Generic; |
|
5
|
|
|
|
|
6
|
|
|
class ExampleRequest extends Generic |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* Called when request iterated. |
|
10
|
|
|
* @return integer Status. |
|
|
|
|
|
|
11
|
|
|
*/ |
|
12
|
|
|
public function run() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->sessionStart(); |
|
15
|
|
|
try { |
|
16
|
|
|
$this->header('Content-Type: text/html'); |
|
17
|
|
|
$this->setcookie('testcookie', '1'); |
|
18
|
|
|
} catch (\PHPDaemon\Request\RequestHeadersAlreadySent $e) { |
|
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
$this->registerShutdownFunction(function () { |
|
22
|
|
|
|
|
23
|
|
|
?> |
|
24
|
|
|
</html> |
|
25
|
|
|
<?php |
|
26
|
|
|
|
|
27
|
|
|
}); |
|
28
|
|
|
|
|
29
|
|
|
if (!isset($_SESSION['counter'])) { |
|
30
|
|
|
$_SESSION['counter'] = 0; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
?> |
|
34
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
35
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml"> |
|
36
|
|
|
<head> |
|
37
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
|
38
|
|
|
<title>It works!</title> |
|
39
|
|
|
</head> |
|
40
|
|
|
<body> |
|
41
|
|
|
<h1>It works! Be happy! ;-) </h1> |
|
42
|
|
|
*Hello world!<br/> |
|
43
|
|
|
Testing Error Message: <?php trigger_error('_text_of_notice_'); |
|
44
|
|
|
?> |
|
45
|
|
|
<br/>Counter of requests to this Application Instance: <b><?php echo ++$this->appInstance->counter; |
|
|
|
|
|
|
46
|
|
|
?></b> |
|
47
|
|
|
<br />Counter in session: <?php echo ++$_SESSION['counter']; |
|
48
|
|
|
?> |
|
49
|
|
|
<br/>Memory usage: <?php $mem = memory_get_usage(); |
|
50
|
|
|
echo($mem / 1024 / 1024); |
|
51
|
|
|
?> MB. (<?php echo $mem; |
|
52
|
|
|
?>) |
|
53
|
|
|
<br/>Memory real usage: <?php $mem = memory_get_usage(true); |
|
54
|
|
|
echo($mem / 1024 / 1024); |
|
55
|
|
|
?> MB. (<?php echo $mem; |
|
56
|
|
|
?>) |
|
57
|
|
|
<br/>My PID: <?php echo getmypid(); |
|
58
|
|
|
?>. |
|
59
|
|
|
<?php |
|
60
|
|
|
|
|
61
|
|
|
$user = posix_getpwuid(posix_getuid()); |
|
62
|
|
|
$group = posix_getgrgid(posix_getgid()); |
|
63
|
|
|
|
|
64
|
|
|
?> |
|
65
|
|
|
<br/>My user/group: <?php echo $user['name'] . '/' . $group['name']; |
|
66
|
|
|
?> |
|
67
|
|
|
<?php |
|
68
|
|
|
|
|
69
|
|
|
$displaystate = true; |
|
70
|
|
|
|
|
71
|
|
|
if ($displaystate) { |
|
72
|
|
|
?><br/><br/><b>State of workers:</b><?php $stat = \PHPDaemon\Core\Daemon::getStateOfWorkers(); |
|
73
|
|
|
?> |
|
74
|
|
|
<br/>Idle: <?php echo $stat['idle']; |
|
75
|
|
|
?> |
|
76
|
|
|
<br/>Busy: <?php echo $stat['busy']; |
|
77
|
|
|
?> |
|
78
|
|
|
<br/>Total alive: <?php echo $stat['alive']; |
|
79
|
|
|
?> |
|
80
|
|
|
<br/>Shutdown: <?php echo $stat['shutdown']; |
|
81
|
|
|
?> |
|
82
|
|
|
<br/>Pre-init: <?php echo $stat['preinit']; |
|
83
|
|
|
?> |
|
84
|
|
|
<br/>Init: <?php echo $stat['init']; |
|
85
|
|
|
?> |
|
86
|
|
|
<br/> |
|
87
|
|
|
<?php |
|
88
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
?> |
|
92
|
|
|
<br/><br/> |
|
93
|
|
|
<br/><br/> |
|
94
|
|
|
|
|
95
|
|
|
<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES); |
|
96
|
|
|
?>" method="post" enctype="multipart/form-data"> |
|
97
|
|
|
<input type="file" name="myfile"/> |
|
98
|
|
|
<input type="submit" name="submit" value="Upload"/> |
|
99
|
|
|
</form> |
|
100
|
|
|
<br/> |
|
101
|
|
|
|
|
102
|
|
|
<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES); |
|
103
|
|
|
?>" method="post"> |
|
104
|
|
|
<input type="text" name="mytext" value=""/> |
|
105
|
|
|
<input type="submit" name="submit" value="Send"/> |
|
106
|
|
|
</form> |
|
107
|
|
|
<pre> |
|
108
|
|
|
<?php |
|
109
|
|
|
|
|
110
|
|
|
var_dump([ |
|
|
|
|
|
|
111
|
|
|
'_GET' => $_GET, |
|
112
|
|
|
'_POST' => $_POST, |
|
113
|
|
|
'_COOKIE' => $_COOKIE, |
|
114
|
|
|
'_REQUEST' => $_REQUEST, |
|
115
|
|
|
'_FILES' => $_FILES, |
|
116
|
|
|
'_SERVER' => $_SERVER |
|
117
|
|
|
]); |
|
118
|
|
|
|
|
119
|
|
|
?></pre> |
|
120
|
|
|
<br/>Request took: <?php printf('%f', round(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'], 6)); |
|
121
|
|
|
//echo '<!-- '. str_repeat('x',1024*1024).' --->'; |
|
122
|
|
|
//echo '<!-- '. str_repeat('x',1024*1024).' --->'; |
|
123
|
|
|
//echo '<!-- '. str_repeat('x',1024*1024).' --->'; |
|
124
|
|
|
?> |
|
125
|
|
|
</body> |
|
126
|
|
|
<?php |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function __destruct() |
|
131
|
|
|
{ |
|
132
|
|
|
Daemon::log('destructed example request'); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.