让node.js在pollingLoop中执行local.php文件
Get node.js to execute local .php file inside pollingLoop
简而言之,这里是我的应用程序的用途。
我有一个PHP文件,通过ODBC连接读取数据,并将它们写入本地数据库。
每当在我的node.js,socket.io服务器中处理循环时,这个PHP文件都需要在服务器上运行LOCAL。
我的设置是Apache、PHP 5.5.12和node.js.
我非常确信有一种简单的方法可以做到这一点,但我没有通过遵循其他指南来获得Ajax或类似的东西来在node.js中工作。
应该在其中处理文件的代码如下所示。
var pollingLoop = function () {
// Update the local database
// HERE I WANT THE PHP FILE TO EXECUTE
// Make the database query
var query = connection.query('SOME LONG SQL QUERY IN HERE'),
status = []; // this array will contain the result of our db query
// set up the query listeners
query
.on('error', function(err) {
// Handle error, and 'end' event will be emitted after this as well
console.log( err );
updateSockets( err );
})
.on('result', function( runningstatus ) {
// it fills our array looping on each runningstatus row inside the db
status.push( runningstatus );
})
.on('end',function(){
// loop on itself only if there are sockets still connected
if(connectionsArray.length) {
pollingTimer = setTimeout(pollingLoop, POLLING_INTERVAL);
updateSockets({status:status});
}
});
};
我尝试那样做完全不符合轨道吗?
尝试通过shell接口调用php:
var exec = require("child_process").exec;
app.get('/', function(req, res){exec("php index.php", function (error, stdout, stderr) {res.send(stdout);});});
或此链接
相关文章:
- 无法在通过jQuery的ajax加载的页面中执行javascript
- JavaScript执行暂时挂起页面
- 如何在ReactJS JSX中执行嵌套的if-else语句
- 当js函数's已执行
- 哪个先执行
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- HTML表单提交时未执行外部函数
- 在Safari执行javascript之前对其进行修改
- Amd,希望确保某个东西总是最后执行
- 在Windows 10中自动执行例行程序(主要与浏览器交互)
- 递归使用 eval() 是检查程序执行的好方法吗?
- 如何做到这一点,使代码在不传递条件后执行函数
- 如何在执行此特定onclick事件时执行JavaScript函数
- 如何在从浏览缓存加载页面时执行javascript
- Jquery表单验证插件-如果选中复选框,如何在提交时执行某些操作
- Jquery:代码在rails中的页面加载时未执行
- 如何防止jQueryonclick事件中的Ruby方法在页面刷新时执行
- JavaScript动画从不执行
- 让node.js在pollingLoop中执行local.php文件
- 如何使用chrome.storage.local.get和XMLHttpRequest同步执行一个函数