Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取node.js以在pollingLoop内执行本地.php文件_Javascript_Php_Node.js_Socket.io_Execute - Fatal编程技术网

Javascript 获取node.js以在pollingLoop内执行本地.php文件

Javascript 获取node.js以在pollingLoop内执行本地.php文件,javascript,php,node.js,socket.io,execute,Javascript,Php,Node.js,Socket.io,Execute,简而言之,这就是我申请的目的 我有一个PHP文件,通过ODBC连接读取数据并将其写入本地数据库 每次在我的node.js、socket.io服务器中处理循环时,都需要在服务器上本地运行此PHP文件 我的设置是Apache、PHP5.5.12和node.js 我非常确信有一种简单的方法可以做到这一点,但我没有通过遵循其他指南在node.js中使用Ajax或类似的方法 应该在其中处理文件的代码如下所示 var pollingLoop = function () { // Update the

简而言之,这就是我申请的目的

我有一个PHP文件,通过ODBC连接读取数据并将其写入本地数据库

每次在我的node.js、socket.io服务器中处理循环时,都需要在服务器上本地运行此PHP文件

我的设置是Apache、PHP5.5.12和node.js

我非常确信有一种简单的方法可以做到这一点,但我没有通过遵循其他指南在node.js中使用Ajax或类似的方法

应该在其中处理文件的代码如下所示

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);});});