簡體   English   中英

獲取node.js以在pollingLoop中執行本地.php文件

[英]Get node.js to execute local .php file inside pollingLoop

簡而言之,這就是我申請的目的。

我有一個PHP文件,它通過ODBC連接讀取數據並將其寫入本地數據庫。

每次在我的node.js,socket.io服務器中處理循環時,都需要在服務器上本地運行此PHP文件。

我的設置是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);});});

此鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM