Short here's the purpose of my application.
I have a PHP file reading data through an ODBC connection and writing them to a local database.
This PHP file needs to be run LOCAL ON THE SERVER each time a loop is processed in my node.js, socket.io server.
My setup is Apache, PHP 5.5.12 and node.js.
I was pretty convinced there was a simple way to this but I haven't had any luck getting Ajax or similar to work inside node.js by following other guides.
The code where the file should be processed inside looks like this.
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});
}
});
};
Am I totally of track by trying to do that?
Try invoking php through the shell interface:
var exec = require("child_process").exec;
app.get('/', function(req, res){exec("php index.php", function (error, stdout, stderr) {res.send(stdout);});});
OR this link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.