Skip to content

Commit 46ba3a3

Browse files
committed
remove watch_path setting.
1 parent 25ffa0b commit 46ba3a3

File tree

4 files changed

+25
-182
lines changed

4 files changed

+25
-182
lines changed

examples/server.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class G
1818
'heartbeat_check_interval' => 30,
1919
'heartbeat_idle_time' => 30,
2020
'open_cpu_affinity' => 1,
21-
//'watch_path' => __DIR__."/php/", //只有PHP5.6支持的语法
2221
//'cpu_affinity_ignore' =>array(0,1)//如果你的网卡2个队列(或者没有多队列那么默认是cpu0来处理中断),并且绑定了core 0和core 1,那么可以通过这个设置避免swoole的线程或者进程绑定到这2个core,防止cpu0,1被耗光而造成的丢包
2322
);
2423

@@ -48,15 +47,15 @@ static function getBuffer($fd, $create = true)
4847
$config['daemonize'] = false;
4948
}
5049

51-
//$mode = SWOOLE_BASE;
52-
$mode = SWOOLE_PROCESS;
50+
$mode = SWOOLE_BASE;
51+
//$mode = SWOOLE_PROCESS;
5352

5453
$serv = new swoole_server("0.0.0.0", 9501, $mode);
5554
$serv->addlistener('0.0.0.0', 9502, SWOOLE_SOCK_UDP);
5655
$serv->addlistener('::', 9503, SWOOLE_SOCK_TCP6);
5756
$serv->addlistener('::', 9504, SWOOLE_SOCK_UDP6);
58-
$process1 = new swoole_process("my_process1", true, false);
59-
$serv->addprocess($process1);
57+
//$process1 = new swoole_process("my_process1", true, false);
58+
//$serv->addprocess($process1);
6059

6160
$serv->set(G::$config);
6261
/**
@@ -73,10 +72,10 @@ function my_process1($process)
7372
global $argv;
7473
var_dump($process);
7574
swoole_set_process_name("php {$argv[0]}: my_process1");
76-
swoole_timer_tick(2000, function($id) {
77-
global $serv;
78-
$serv->sendMessage("hello", 1);
79-
});
75+
// swoole_timer_tick(2000, function($id) {
76+
// global $serv;
77+
// $serv->sendMessage("hello", 1);
78+
// });
8079
}
8180

8281
function my_onStart(swoole_server $serv)
@@ -141,7 +140,7 @@ function setTimerInWorker(swoole_server $serv, $worker_id) {
141140

142141
if ($worker_id == 0) {
143142
echo "Start: ".microtime(true)."\n";
144-
$serv->addtimer(3000);
143+
//$serv->addtimer(3000);
145144
// $serv->addtimer(7000);
146145
//var_dump($serv->gettimer());
147146
}
@@ -155,6 +154,15 @@ function setTimerInWorker(swoole_server $serv, $worker_id) {
155154
// });
156155
}
157156

157+
function onWorkerStart(swoole_server $serv, $worker_id)
158+
{
159+
if (!$serv->taskworker) {
160+
$serv->tick(1000, function ($id) {
161+
var_dump($id);
162+
});
163+
}
164+
}
165+
158166
function my_onShutdown($serv)
159167
{
160168
echo "Server: onShutdown\n";
@@ -193,6 +201,10 @@ function my_onWorkerStart($serv, $worker_id)
193201
swoole_process::signal(SIGUSR2, function($signo){
194202
echo "SIGNAL: $signo\n";
195203
});
204+
205+
swoole_timer_tick(2000, function($id) {
206+
var_dump($id);
207+
});
196208
}
197209
//forkChildInWorker();
198210
// setTimerInWorker($serv, $worker_id);
@@ -415,6 +427,9 @@ function broadcast(swoole_server $serv, $fd = 0, $data = "hello")
415427
var_dump($src_worker_id, $msg);
416428
});
417429

430+
431+
swoole_timer_tick(2000, function($id) {var_dump($id);});
432+
418433
$serv->on('Start', 'my_onStart');
419434
$serv->on('Connect', 'my_onConnect');
420435
$serv->on('Receive', 'my_onReceive');

include/Server.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ struct _swServer
380380

381381
uint8_t listen_port_num;
382382

383-
char *watch_path;
384383
time_t reload_time;
385384

386385
/**

src/network/Server.c

Lines changed: 0 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
#include "Http.h"
1919
#include "Connection.h"
2020

21-
#ifdef HAVE_INOTIFY
22-
#include <dirent.h>
23-
#include <sys/inotify.h>
24-
#endif
25-
2621
#if SW_REACTOR_SCHEDULE == 3
2722
static sw_inline void swServer_reactor_schedule(swServer *serv)
2823
{
@@ -45,13 +40,6 @@ static void swServer_signal_hanlder(int sig);
4540
static int swServer_start_proxy(swServer *serv);
4641
static void swServer_disable_accept(swReactor *reactor);
4742

48-
#ifdef HAVE_INOTIFY
49-
static swHashMap *watch_file_map = NULL;
50-
static int swServer_master_onFileChange(swReactor *reactor, swEvent *event);
51-
static int swServer_master_add_watch(int ifd, char *dirname);
52-
static void swServer_master_check_reload_time();
53-
#endif
54-
5543
static void swHeartbeatThread_loop(swThreadParam *param);
5644
static int swServer_send1(swServer *serv, swSendData *resp);
5745
static int swServer_send2(swServer *serv, swSendData *resp);
@@ -97,149 +85,6 @@ void swServer_enable_accept(swReactor *reactor)
9785
}
9886
}
9987

100-
#ifdef HAVE_INOTIFY
101-
int swServer_watch_file(swServer *serv, swReactor *reactor)
102-
{
103-
#ifdef HAVE_INOTIFY_INIT1
104-
int ifd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
105-
#else
106-
int ifd = inotify_init();
107-
#endif
108-
if (ifd < 0)
109-
{
110-
swSysError("inotify_init() failed.");
111-
return SW_ERR;
112-
}
113-
#ifndef HAVE_INOTIFY_INIT1
114-
swSetNonBlock(ifd);
115-
#endif
116-
if (ifd < 0)
117-
{
118-
return SW_ERR;
119-
}
120-
if (swServer_master_add_watch(ifd, serv->watch_path) < 0)
121-
{
122-
return SW_ERR;
123-
}
124-
125-
reactor->setHandle(reactor, SW_FD_INOTIFY, swServer_master_onFileChange);
126-
reactor->atLoopEnd(reactor, swServer_master_check_reload_time);
127-
128-
return reactor->add(reactor, ifd, SW_FD_INOTIFY | SW_EVENT_READ);
129-
}
130-
131-
static void swServer_master_check_reload_time()
132-
{
133-
swServer *serv = SwooleG.serv;
134-
if (serv->reload_time > 0 && SwooleGS->now > serv->reload_time)
135-
{
136-
swKill(SwooleGS->manager_pid, SIGUSR1);
137-
serv->reload_time = 0;
138-
}
139-
}
140-
141-
static int swServer_master_add_watch(int ifd, char *dirname)
142-
{
143-
char subdir[512];
144-
struct dirent *child_dir;
145-
146-
DIR *odir = opendir(dirname);
147-
if (odir == NULL)
148-
{
149-
swSysError("opendir(%s) failed.", dirname);
150-
return SW_ERR;
151-
}
152-
153-
int mask = IN_MODIFY | IN_MOVED_FROM | IN_CREATE | IN_DELETE | IN_ISDIR;
154-
155-
int watch_fd = inotify_add_watch(ifd, dirname, mask);
156-
if (watch_fd < 0)
157-
{
158-
swSysError("inotify_add_watch(%s) failed.", dirname);
159-
return SW_ERR;
160-
}
161-
162-
if (watch_file_map == NULL)
163-
{
164-
watch_file_map = swHashMap_new(16, NULL);
165-
}
166-
swHashMap_add_int(watch_file_map, watch_fd, strdup(dirname), NULL);
167-
168-
errno = 0;
169-
while ((child_dir = readdir(odir)) != NULL)
170-
{
171-
if (strcmp(child_dir->d_name, ".") == 0 || strcmp(child_dir->d_name, "..") == 0)
172-
{
173-
continue;
174-
}
175-
if (child_dir->d_type == DT_DIR)
176-
{
177-
sprintf(subdir, "%s/%s", dirname, child_dir->d_name);
178-
swServer_master_add_watch(ifd, subdir);
179-
}
180-
}
181-
182-
if (errno != 0)
183-
{
184-
swSysError("readdir(%s) failed.", dirname);
185-
}
186-
187-
closedir(odir);
188-
return watch_fd;
189-
}
190-
191-
/**
192-
* Application file is changed.
193-
*/
194-
static int swServer_master_onFileChange(swReactor *reactor, swEvent *event)
195-
{
196-
swServer *serv = SwooleG.serv;
197-
char name[1024];
198-
struct inotify_event *ievent;
199-
char buf[sizeof(struct inotify_event) * 128];
200-
int n, i;
201-
int ifd = event->fd;
202-
203-
while (1)
204-
{
205-
n = read(ifd, buf, sizeof(buf));
206-
if (n <= 0)
207-
{
208-
break;
209-
}
210-
211-
for (i = 0; i < n; i += sizeof(struct inotify_event) + ievent->len)
212-
{
213-
ievent = (struct inotify_event*) &buf[i];
214-
if (ievent->mask & IN_ISDIR)
215-
{
216-
if (ievent->mask & IN_CREATE)
217-
{
218-
char *parent_dir_name = swHashMap_find_int(watch_file_map, ievent->wd);
219-
snprintf(name, sizeof(name), "%s/%s", parent_dir_name, ievent->name);
220-
swServer_master_add_watch(ifd, name);
221-
}
222-
else
223-
{
224-
inotify_rm_watch(ifd, ievent->wd);
225-
}
226-
}
227-
else
228-
{
229-
if (ievent->len > (sizeof(SW_RELOAD_FILE_EXTNAME) - 1)
230-
&& strcasecmp(ievent->name + strlen(ievent->name) - (sizeof(SW_RELOAD_FILE_EXTNAME) - 1),
231-
SW_RELOAD_FILE_EXTNAME) == 0)
232-
{
233-
serv->reload_time = SwooleGS->now + SW_RELOAD_AFTER_SECONDS_N;
234-
swNotice("Program files is changed, Server will reload after %d seconds.", SW_RELOAD_AFTER_SECONDS_N);
235-
}
236-
}
237-
}
238-
}
239-
return SW_OK;
240-
}
241-
#endif
242-
24388
int swServer_master_onAccept(swReactor *reactor, swEvent *event)
24489
{
24590
swServer *serv = reactor->ptr;
@@ -526,16 +371,6 @@ static int swServer_start_proxy(swServer *serv)
526371
main_reactor->ptr = serv;
527372
main_reactor->setHandle(main_reactor, SW_FD_LISTEN, swServer_master_onAccept);
528373

529-
#ifdef HAVE_INOTIFY
530-
/**
531-
* inotify, watch the application file update.
532-
*/
533-
if (serv->watch_path)
534-
{
535-
swServer_watch_file(serv, main_reactor);
536-
}
537-
#endif
538-
539374
if (serv->onStart != NULL)
540375
{
541376
serv->onStart(serv);

swoole_server.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,12 +1286,6 @@ PHP_FUNCTION(swoole_server_set)
12861286
convert_to_long(v);
12871287
serv->backlog = (int) Z_LVAL_P(v);
12881288
}
1289-
//watch_path
1290-
if (sw_zend_hash_find(vht, ZEND_STRS("watch_path"), (void **) &v) == SUCCESS)
1291-
{
1292-
convert_to_string(v);
1293-
serv->watch_path = strndup(Z_STRVAL_P(v), Z_STRLEN_P(v));
1294-
}
12951289
//reactor thread num
12961290
if (sw_zend_hash_find(vht, ZEND_STRS("reactor_num"), (void **) &v) == SUCCESS)
12971291
{

0 commit comments

Comments
 (0)