Using Mongo with PHPCloud

With the release that occurred on March 4th we have added Mongo support to the DevCloud.  So connecting to a Mongo instance is extremely easy to do now.  We don’t provide access to a Mongo collection but you do have the tools to connect to various Mongo service providers.  For this example I used MongoHQ though any service running Mongo sound work.

First go to whichever service you are using and create a new collection.  Like this

Then click on the Zend Server link for your container.  Like this

Go to Server Setup / Extensions and enable Mongo.  Like this

Restart Zend Server and deploy code.  Like this

1
2
3
4
5
6
7
8
9
10
11
$db = new Mongo('mongodb://kschroeder:[email protected]:10050/kschroeder');
 
$collection = $db->kschroeder->views;
 
$collection->insert(
array(
'view' => new MongoDate()
)
);
 
echo $collection->count() . ' views on this page';

Now you’re doing Mongo on the DevCloud like a boss.

It took me all of 10 minutes to do this.

3 Thoughts on “Using Mongo with PHPCloud

  1. azharuddin31 on March 12, 2012 at 4:59 pm said:

    This seems to be pretty easy..

  2. SamuelCarlier on April 4, 2012 at 2:32 am said:

    is mongohq on the same network as zendserver? other wise the latency will be unacceptable

    • kschroeder on April 4, 2012 at 7:52 am said:

       @SamuelCarlier For development purposes it would be fine unless you’re dealing with huge amounts of data.  My own testing has shown that while there is additional latency, it’s not actually too bad.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Post Navigation

Web Analytics