28
28
To bind a socket,
29
29
<literal >listen</literal >,
30
30
and
31
- <literal >
32
- accept</literal >
33
- connections on the socket in s single call use
31
+ <literal >accept</literal >
32
+ connections on the socket in a single call use
34
33
<methodname >EventHttp::bind</methodname >.
35
34
<methodname >EventHttp::accept</methodname >
36
35
is needed only if one already has a socket ready to accept connections.
67
66
<programlisting role =" php" >
68
67
<![CDATA[
69
68
<?php
69
+
70
70
$base = new EventBase();
71
71
$http = new EventHttp($base);
72
72
73
- $addresses = array (
74
- 8091 => "127.0.0.1",
75
- 8092 => "127.0.0.2",
76
- ) ;
73
+ $addresses = [
74
+ 8091 => "127.0.0.1",
75
+ 8092 => "127.0.0.2",
76
+ ] ;
77
77
$i = 0;
78
78
79
79
$socket = array();
80
80
81
81
foreach ($addresses as $port => $ip) {
82
82
echo $ip, " ", $port, PHP_EOL;
83
83
$socket[$i] = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
84
+
84
85
if (!socket_bind($socket[$i], $ip, $port)) {
85
86
exit("socket_bind failed\n");
86
87
}
88
+
87
89
socket_listen($socket[$i], 0);
88
90
socket_set_nonblock($socket[$i]);
89
91
@@ -95,14 +97,14 @@ foreach ($addresses as $port => $ip) {
95
97
++$i;
96
98
}
97
99
98
- $http->setCallback("/some-page", function() {
99
- echo "(some-page)\n";
100
+ $http->setCallback("/some-page", function () {
101
+ echo "(some-page)\n";
100
102
echo "URI: ", $req->getUri(), PHP_EOL;
101
103
$req->sendReply(200, "OK");
102
104
echo "OK\n";
103
105
});
104
106
105
- $http->setDefaultCallback(function($req) {
107
+ $http->setDefaultCallback(function ($req) {
106
108
echo "URI: ", $req->getUri(), PHP_EOL;
107
109
$req->sendReply(200, "OK");
108
110
echo "OK\n";
0 commit comments