Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

MongoConnectionException doesn't exists for hhvm #46

Open
ezruneko opened this issue Sep 9, 2015 · 4 comments · May be fixed by #47
Open

MongoConnectionException doesn't exists for hhvm #46

ezruneko opened this issue Sep 9, 2015 · 4 comments · May be fixed by #47

Comments

@ezruneko
Copy link

ezruneko commented Sep 9, 2015

I installed on Ubuntu 14.04LTS MongoDB module in drupal:

curl http://ftp.drupal.org/files/projects/drupal-7.39.tar.gz | tar xvz
curl http://ftp.drupal.org/files/projects/mongodb-7.x-1.x-dev.tar.gz | tar xvz

# hhvm --version
HipHop VM 3.9.1 (rel)
Compiler: tags/HHVM-3.9.1-0-g0f72cfc2f0a01fdfeb72fbcfeb247b72998a66db
Repo schema: 6416960c150a4a4726fda74b659105ded8819d9c

# apt-show-versions hhvm-dev
hhvm-dev:amd64/trusty 3.9.1~trusty uptodate

And crash in line 58 in mongo.module:

\nFatal error: Class undefined: MongoConnectionException in /usr/share/nginx/closure.es/blog/sites/all/modules/mongodb/mongodb.module on line 58
//Line 58 => $mongo = new MongoClient($host, $options);

The snippet code:

    try {
      // Use the 1.3 client if available.
      if (class_exists('MongoClient')) {
        $mongo = new MongoClient($host, $options); //<-- LINE: 58
        // Enable read preference and tags if provided. This can also be
        // controlled on a per query basis at the cursor level if more control
        // is required.
        if (!empty($connection['read_preference'])) {
          $tags = !empty($connection['read_preference']['tags']) ? $connection['read_preference']['tags'] : array();
          $mongo->setReadPreference($connection['read_preference']['preference'], $tags);
        }
      }
      else {
        $mongo = new Mongo($host, $options);
        if (!empty($connection['slave_ok'])) {
          $mongo->setSlaveOkay(TRUE);
        }
      }
      $mongo_objects[$host][$db] = $mongo->selectDB($db);
      $mongo_objects[$host][$db]->connection = $mongo;
    }
    catch (MongoConnectionException $e) {
      $mongo_objects[$host][$db] = new MongoDummy();
      throw $e;
    }

But when i try a simple example like:

<?php

try {
$m = new MongoClient(); // connect
$db = $m->foo; // get the database named "foo"
}
catch (MongoConnectionException $e) {
    print_r($e);
}

?>

Any error is reported in the hhvm/error.log. Bug is generated when hhvm compile the php file because if i add a print_r($host) before $mongo = new MongoClient($host, $options); don't show my print_r()

Another test

<?php

echo 'HHVM version: ' . phpversion() . '<br/>';
echo 'MongoFill version: ' . phpversion('mongo') . '<br/>';
echo '-----------------------------------------<br/>';
echo 'MongoClient: ' . (class_exists('MongoClient') ? 'true' : 'false') . '<br/>';
echo 'MongoConnectionException: ' . (class_exists('MongoConnectionException') ? 'true' : 'false') . '<br/>';
echo 'MongoException: ' . (class_exists('MongoException') ? 'true' : 'false');

?>
//Output:
HHVM version: 5.6.99-hhvm
MongoFill version: 1.4.5
-----------------------------------------
MongoClient: true
MongoConnectionException: false
MongoException: true

Live version: http://closure.es/mongo.php


Updated:

  • I've tried to recompile mongofill-hhvm and redownload from git
  • I've reinstalled Drupal
  • I've tested with 2 versions (dev and stable version) of Mongo Module for Drupal
  • reboot hhvm, nginx and mongo
  • reboot the machine
  • Mongo is up with service --status-all
  • With the mongo command i can add, list and remove dbs

And seems that hhvm dont find the MongoConnectionException class.

  • In my src/ext_mongo.php file the class MongonConnectionException exists
  • But when i use get_declared_classes (); in hhvm dont show the MongoConnection Exception:
    https://gist.github.com/layane/1d7887d0ceb94ee207fe
  • So I confirm that hhvm dont find the MongoConnectionException class
  • I ugly resolve this bug, adding MongoConnectionException.php to my Drupal and importing with require_once();
@ezruneko ezruneko changed the title Crash with Drupal/MongoDB MongoConnectionException doesn't exists for hhvm Sep 9, 2015
@ezruneko
Copy link
Author

ezruneko commented Sep 9, 2015

Solved:

I rename in MongoFill the file MongoException.php to AMongoException.php and recompile it. So the problem is the order to merge all php files in the ext_mongo.php.

MongoException must be parsed before all inherited classes.

//Test: http://closure.es/mongo.php
HHVM version: 5.6.99-hhvm
MongoFill version: 1.4.5
-----------------------------------------
MongoClient: true
MongoConnectionException: true
MongoException: true

The same occurs with the Mongo class (Mongo.php). I need to rename to AMongo.php to extends from MongoClient

rowillia pushed a commit to rowillia/mongofill-hhvm that referenced this issue Sep 12, 2015
@rowillia
Copy link

I have a fix for this in #47

@ProdigyView
Copy link

I surmise this would fix my issue: #45

@ezruneko
Copy link
Author

@rowillia perfect solution is more elegant that rename base classes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants