-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
175 lines (113 loc) · 3.54 KB
/
server.js
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
const PORT = 8080;
const ADDRESS = '0.0.0.0';
var PHPFPM = require('/usr/local/etc/node_modules/node-phpfpm');
var serialport = require('serialport');
var SerialPort = serialport.SerialPort;
var parsers = serialport.parsers;
//var SerialPort = require('serialport').SerialPort;
//var parsers = serialport.parsers;
/*var port = new SerialPort('/dev/cu.usbserial',{
baudrate: 115200,
parser: parsers.readline('\r\n'),
});*/
//var PHPFPM = require('./nodejs/node-phpfpm');
var phpfpm = new PHPFPM(
{
host: '127.0.0.1',
port: 9000,
//documentRoot: __dirname + '/',
documentRoot: '/WEBDEV/sms101.dev/',
});
/*console.log(phpfpm);
phpfpm.run('sms3.php', function(err, output, phpErrors)
{
if (err == 99) console.error('PHPFPM server error');
console.log(output);
if (phpErrors) console.error(phpErrors);
});*/
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
//res.end('Hello World\n');
//console.log(req);
//console.log(res);
console.log('req.method => '+req.method);
console.log('req.url => '+req.url);
if(req.url==='/start') {
phpfpm.run('test101.php?q=start', function(err, output, phpErrors)
{
if (err == 99) console.error('PHPFPM server error');
console.log(output);
if (phpErrors) console.error(phpErrors);
});
} else
if(req.url==='/end') {
phpfpm.run('test101.php?q=end', function(err, output, phpErrors)
{
if (err == 99) console.error('PHPFPM server error');
console.log(output);
if (phpErrors) console.error(phpErrors);
});
} else
if(req.url==='/init') {
phpfpm.run('sms3.php?q=init', function(err, output, phpErrors)
{
if (err == 99) console.error('PHPFPM server error');
console.log(output);
if (phpErrors) console.error(phpErrors);
});
} else
if(req.url==='/balance') {
phpfpm.run('sms3.php?q=balance', function(err, output, phpErrors)
{
if (err == 99) console.error('PHPFPM server error');
console.log(output);
if (phpErrors) console.error(phpErrors);
});
} else
if(req.url==='/check') {
phpfpm.run('sms3.php?q=check', function(err, output, phpErrors)
{
if (err == 99) console.error('PHPFPM server error');
console.log(output);
if (phpErrors) console.error(phpErrors);
});
}
res.end('end.\n');
});
/*port.on('open', function () {
port.write("AT\r\n", function(err, bytesWritten) {
if (err) {
return console.log('Error: ', err.message);
}
console.log(bytesWritten, 'bytes written');
});
});
port.on('data', function (data) {
console.log('Data: ' + data);
});*/
server.listen(PORT, ADDRESS, function () {
console.log('Server running at http://%s:%d/', ADDRESS, PORT);
console.log('Press CTRL+C to exit');
});
/*var ctr=0;
setInterval(function(){
console.log('setInterval: '+ctr);
ctr++;
phpfpm.run('sms3.php?q=check', function(err, output, phpErrors)
{
if (err == 99) console.error('PHPFPM server error');
console.log(output);
if (phpErrors) console.error(phpErrors);
});
},60000);*/
function doCheck() {
phpfpm.run('sms3.php?q=check', function(err, output, phpErrors)
{
if (err == 99) console.error('PHPFPM server error');
console.log(output);
setTimeout(doCheck, 10000);
if (phpErrors) console.error(phpErrors);
});
}
doCheck();