我在node.js中有一个简单的队列显示应用程序。它将用户显示在显示器上的队列中。应用运行正常。我们目前在许多服务器上运行它。问题是,在一些服务器上,一段时间后(永远列表显示一个示例运行15天)它停止响应并且netstat显示没有监听端口3000.
代码:
// Module dependindex.html
var express = require('express'),
mysql = require('mys');
// Application initialization
var connection = mysql.createConnection({
host : 'mysql.host',
user : 'root',
password : 'pw',
database : 'db',
});
var app = express();
app.use(express.urlencoded());
app.use(express.static(__dirname + '/components'));
// Page configuration (html pages are tempulates)
app.get('/', function(req,res) {
res.sendfile(__dirname + '/index.html');
});
// Application routes
// mysql calls/logic here
app.post('/', function(req, res){
var query = "SELECT aa.id, aa.first_name, aa.last_name, aa.gwf, ac.counter_stage, aa.queue_call_by_flag, ac.counter_name FROM `agent_counters` ac LEFT JOIN `applicants` aa ON aa.id = ac.next_applicant WHERE ac.call_next = 1 AND ac.next_applicant is not null";
connection.query(query, req.body, function(err, rows, fields) {
if (err) throw err;
var obj = {};
var prop = "";
var gwf_name = ""
for (var i = 0; i < rows.length; i++) {
var current_stage = "";
switch (rows[i].counter_stage) {
case "documentation":
current_stage = "Documentation";
break;
case "biometrics":
current_stage = "Biometrics";
break;
case "interview":
current_stage = "Interview";
break;
}
prop = "gwf" + i;
if (rows[i].queue_call_by_flag == 'gwf') {
gwf_name = rows[i].gwf;
} else {
gwf_name = rows[i].first_name + ' ' + rows[i].last_name;
}
obj[prop] = gwf_name + '|' + rows[i].counter_name + '|' + current_stage + '|' + rows[i].id;
}
res.send(JSON.stringify(obj));
});
});
// Begin listening
app.listen(3000);
console.log("Express server listening on port %d in %s mode", '3000', app.settings.env);
我已将服务器设置为使用Forever模块Forever运行命令:
Forever start app.js
任何帮助都将不胜感激。