0

I have a cloud of virtual servers: one running php, one running node.js, one running mongodb.

Dnode has successfully passed messages between the php and node using this guide.

<?php
// Include Composer-generated autoloader
require(__DIR__.'/vendor/autoload.php');
// Fed from NODE Server
$mongo = new React\EventLoop\StreamSelectLoop();
// Connect to DNode server running in port 7071 and call query to display
$dnode = new DNode\DNode($mongo);
$dnode->connect(7071, '192.168.15.29', function($remote, $connection) {
$remote->MongoQ(use ($connection){
echo;
$connection->end();
});
});
$mongo->run();
?>  

Node has successfully connected to mongo using this guide.

//Retrieve
var MongoClient = require('mongodb').MongoClient;
// Connect to the db
MongoClient.connect("mongodb://192.168.15.26:27017/mongotest", function(err, db) {
if(err) { return console.dir(err); }
var collection = db.collection('usercollection');
collection.find().pretty()
});
});
// Feed to PHP Client
var dnode = require('dnode');
var server = dnode({
MongoQ: function() {collection.find().toArray(function(err, items) {});}
});
server.listen(7071, '192.168.15.29');
console.log('Server running at http://192.168.15.29:7071/');

I'm completely lost as to what to do on the PHP side once I've called the function that queries my mongo collection.

  • 1
    This approach to querying seems slightly convoluted; is there a reason you don't want to connect to MongoDB directly from both environments (or choose one environment, and provide a restful API rather than RPC access)? – Stennie Jul 07 '14 at 00:36
  • You're correct. I was attempting a model view controller type setup, but it was a big mess. I switched to using just Node and Mongo, with Angular as a front end templating engine. Thanks for the honest feedback. – Chelsea Wuest Sep 21 '14 at 20:01

0 Answers0