-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmanual.html
executable file
·237 lines (220 loc) · 11.3 KB
/
manual.html
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE HTML>
<html>
<head>
<!--[if lt IE 7]>
<script type="text/javascript">location.replace('/ie6/ie6.html');</script><noscript><meta http-equiv="refresh" content="0; url=/ie6/ie6.html"></noscript>
<![endif]-->
<meta charset="utf-8">
<meta name="keywords" content="phpDaemon, daemon.io, async, I/O, daemon, php, FAQ" />
<meta name="description" content="Asynchronous server-side framework for Web and network applications implemented in PHP using libevent, phpDaemon can handle thousands of simultaneous connections" />
<title>Manual « phpDaemon</title>
<link rel="stylesheet" type="text/css" href="/css/style.css">
<link rel="stylesheet" type="text/css" href="/css/add.css">
<link rel="stylesheet" type="text/css" href="/css/shi_default.min.css">
<link rel="shortcut icon" href="/favicon.png" type="image/png" />
<link rel="icon" href="/favicon.png" type="image/png" />
<!--[if lte IE 9]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link type="text/css" rel="stylesheet" href="/css/ie.css">
<![endif]-->
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<link type="text/css" rel="stylesheet" href="/css/ie8.css">
<![endif]-->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-40317559-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id="template">
<header>
<div class="center">
<a href="/" id="logo" title="phpDaemon">phpDaemon</a>
<a href="/download.html" id="download" title="Download">DOWNLOAD</a>
<menu>
<li><span><a href="/examples.html" title="Examples">Examples</a></span></li>
<li><span><a href="/faq.html" title="FAQ">FAQ</a></span></li>
<li><span><a href="/docs/" title="Documentation">Documentation</a></span></li>
<li><span><a href="https://github.com/kakserpom/phpdaemon/issues" title="Tracker" target="_blank">Tracker</a></span></li>
<li><span><a href="/team.html" title="Team">Team</a></span></li>
<li><span><a href="/contribute.html" title="Contribute">Contribute</a></span></li>
<li><span><a href="/publications.html" title="Publications">Publications</a></span></li>
</menu>
</div>
</header>
<aside>
<div class="saw"></div>
<div class="center">
<div class="caption">
<h1 class="manual_caption">Manual</h1>
<p>
This manual describes techniques of programming and maintaining applications in phpDaemon.
</p>
</div>
</div>
</aside>
<div id="main" class="clearfix">
<div>
<section>
<div class="section">
<div class="center">
<h2><a href="#intro">Introduction</a></h2>
<div class="accordion-content opened" style="display: block;">
<br>
<p>First of all, let me tell you what phpDaemon is. In accordance with its name, it is the network daemon built using libevent2 and eio. phpDaemon has completely asynchronous nature.
What does it mean? It means that in strong contradiction to standard Apache plus PHP, phpDaemon’s workers never block (never call <a href="http://php.net/sleep" target="_blank">sleep()</a> function). If you use PHP, in the standard way, and call any I/O function (e.g. mysql_query, fread/fwrite), these functions block the process until the operation is complete.<br>
<br>Therefore, if your script sends query to database and it takes 1 second, memory taken by PHP process is locked for 1 second. <br>Therefore, if you have 1 GB of available memory and each Apache worker takes 10 MB (it takes much more in real world), your system can handle ~100 concurrent requests at most. Response delay becomes very valuable thing. If your network or database (or any other I/O source) is lagging under the load, each request will take more time, and requests per second (RPS) goes down.<br>
In the same circumstances, phpDaemon is able to handle all of these requests using ~10 mb per CPU core, and delay of each HTTP reply does not matter at all.<br>When phpDaemon gets incoming HTTP request, it creates object of YourAppRequest class, and just destroys the object after all.</p>
</div>
</div>
</div>
</section>
<section class="odd">
<div class="section">
<div class="center">
<h2><a href="#gettingstarted">Getting Started</a></h2>
<div>
<p>
<br>
<p>First of all, go to <a href="/download.html">Download</a> page and follow the instructions.</p><br />
<p>Once you finished that instructions, you should create <b>conf/phpd.conf file</b>. You can copy it from <b>phpd.conf.example</b></p>
<p>After that, you need to configure your phpDaemon instance by adding applications to config file, they will be started at the daemon start.</p>
<p>To start phpDaemon normally you should run <b>phpd start</b>, but for debugging purposes and initial setup we recommend you to use <b>runworker</b> command (non-fork mode with 1 worker) with <i>--verbose-tty-1</i> (log messages to STDOUT).</p>
<br />$ <input type="text" class="copysnippet" readonly="readonly" value="phpd runworker --verbose-tty=1" size="60" /><br /><br />
</p>
<p> Next, run the most simple application - "Ping Pong telnet service." Edit config file /opt/phpdaemon/conf/phpd.conf. File must be something like this
<blockquote><xmp>
## Config file
user [your user];
group [your group];
max-workers 8;
min-workers 8;
start-workers 8;
max-idle 0;
#add-include-path '/path/to/your/folder';
Pool:\PHPDaemon\Examples\ {
listen 'tcp://0.0.0.0:23';
}
</xmp></blockquote>
And try -
<br />$ <input type="text" class="copysnippet" readonly="readonly" value="sudo phpd restart --verbose-tty=1" size="36" /><br />
Must be result -
<blockquote><xmp>
[PHPD] Loaded config file: '/opt/phpdaemon/conf/phpd.conf'
[PHPD] M#387 \PHPDaemon\Core\Pool:\PHPDaemon\Examples\TelnetHoneypot up.
</xmp></blockquote>
$ <input type="text" class="copysnippet" readonly="readonly" value="telnet localhost 23" size="20"/><br />
<blockquote><xmp>
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
ping
pong
do-something
Unknown command "do-something"
quit
Quit
</xmp></blockquote>
This only supports 2 commands - ping and quit. We run first application on phpDaemon. You can experiment with this example, edit the file <i>/opt/phpdaemon/PHPDaemon/Examples/TelnetHoneypot.php</i> write your own application. Good luck. </p>
</div>
</div>
</div>
</section>
<section>
<div class="section">
<div class="center">
<h2><a href="#config">Configuration</a></h2>
<div>
<br /><p>
Configuration is defined by the main config-file (and included config files).
Syntax of config files is <b>pretty intuitive</b>. Here is a list of rules:<br><br />
<ol>
<li>Lines beginning with # are treated as comments and ignored. Example: # Some text</li>
<li>White-spaces outside of quoted strings are ignored.</li>
<li>Lines beginning with alphanumeric and ending with <b>semicolon</b> are setting definitions. Example: <b>user john;</b></li>
<li>Multi-line definitions must have backslash and the end of each line.</li>
<li>Lines (and group of lines) beginning with alphanumeric and ending with '{' is a start of nested block. Character '}' closes the block.</li>
<li>Numeric unquoted sequences are treated as numbers.</li>
<li>Single-quoted (') strings are similar to PHP. Therefore \' means '.</li>
<li>Double-quoted (") strings are similar to PHP, except dollar syntax. Therefore \" means ". Hexadecimal and decimal escaped sequences are supported (for instance \x20 means chr(hexdec('20')) byte and \32 means chr(32) byte).</li>
</ol>
<br />Syntax rules do not depend on concrete definition or block name, they are general.
</p><br /><p>Let's take look at the packaged example of main config file:
<blockquote><xmp>
## Config file
#user john;
#group workgroup;
max-workers 8;
min-workers 8;
start-workers 8;
max-idle 0;
\Your\Application {
# config of your application which class is "\Your\Application"
}
# other applications...
include conf.d/*.conf;
</xmp></blockquote>
<br />
At the top level, the following directives are available:<br /><br />
<table class="tblManual">
<tr>
<th style="width: 200px">Name</th>
<th style="width: 200px">Default</th>
<th>Description</th>
</tr>
<tr>
<td>max-memory-usage</td>
<td>0b</td>
<td>Maximum memory usage for graceful restart of worker</td>
</tr>
</table>
<br /><p>
</p>
</div>
</div>
</div>
</section>
<section class="odd">
<div class="section">
<div class="center">
<h2><a href="#capabilities">What types of applications can I develop using this?</a></h2>
<div>
<br>
<p>Any kind of Web or network application, you can combine different things in one application. For instance, you can easily build HTTP service which will communicate with external server, e.g. Stratus. Or you can build Jabber or IRC web gate.</p>
</div>
</div>
</div>
</section>
</div>
</div>
<footer>
<div class="center">
<a href="http://validator.w3.org/check?uri=http%3A%2F%2Fdaemon.io%2F" title="W3C HTML 5" target="_blank" class="w3chtml5"><img src="/img/w3chtml5.png" alt="W3C HTML 5" width="88" height="31"></a>
Feel free to send Pull Requests with additions/changes to this manual.
</div>
</footer>
<div class="scrollup"></div><div class="scrolldown"></div>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_floating_style addthis_16x16_style" style="top:50px;background:none;opacity:0.70">
<a class="addthis_button_twitter" addthis:title="#Asynchronous server-side framework for Web and network applications implemented in #PHP using libevent, check out" addthis:url="http://daemon.io/"></a>
<a class="addthis_button_reddit"></a>
<a class="addthis_button_facebook"></a>
<a class="addthis_button_google_plusone_share"></a>
<a class="addthis_button_digg"></a>
<a class="addthis_button_compact"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#domready=1"></script>
<!-- AddThis Button END -->
<a href="https://github.com/kakserpom/phpdaemon" class="forkButton" target="_blank"><img src="/img/forkme.png" height="149" width="149" alt="Fork me on GitHub"></a>
</body>
</html>