将PHP升级到版本7后,为什么不能使用mongodb驱动程序? [英] After upgrading PHP to version 7, why can't I use the mongodb driver?

查看:122
本文介绍了将PHP升级到版本7后,为什么不能使用mongodb驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这是我发现的一种奇怪情况.我一直在一个项目上一起使用PHP和MongoDB,并更新了相关的软件.升级后,我确实确保更新了新的conf文件,一切都很好---除非尝试使用MongoClient类时,我遇到以下致命错误:

Well here's an odd situation I've found. I've been using PHP and MongoDB together on a project, and updated the associated software. After the upgrade, I did make sure to update the new conf files and all is well --- except when I try to use the MongoClient class, I get the following fatal error:

致命错误:未捕获的错误:在/srv/http/test.php中找不到类'MongoClient'

Fatal error: Uncaught Error: Class 'MongoClient' not found in /srv/http/test.php

所以我的第一个直觉是检查我的/etc/php/php.ini以确保正确包含了mongodb.so.我在其他extension行之后找到了它:

So my first instinct was to check my /etc/php/php.ini to make sure that mongodb.so was correctly included. I found it after the other extension lines:

extension=mcrypt.so
extension=zip.so
extension=mongodb.so ; <--- here it is

选中该选项,我加载了一个快速的phpinfo()脚本,以检查我是否使用了正确的php.ini文件,并确认我使用了正确的文件.不仅如此,mongodb驱动程序似乎也已正确加载!

With that checked, I loaded up a quick phpinfo() script to check that I was using the right php.ini file, and confirmed that I am. And not only that, the mongodb driver also appears to be loaded correctly!

Loaded Configuration File      /etc/php/php.ini
. . .
mongodb support                enabled
mongodb                        version      1.1.1
mongodb                        stability    stable
libmongoc                      version      1.3.1-dev
libbson                        version      1.3.0

因此,我重新启动了httpd并再次尝试.没有骰子,仍然找不到MongoClient类.因此,我尝试从pecl而非发行版的程序包管理器安装它,情况与上述相同.

So I restarted httpd and tried again. No dice, still can't find the MongoClient class. So I tried to install it from pecl instead of my distribution's package manager, and the situation is the same as described above.

所以这是情况的简要介绍:

So here's a quick rundown of the situation:

  • Linux内核4.3.3
  • PHP版本7.0.1
  • php-mongodb版本1.1.1
    • Linux kernel 4.3.3
    • PHP Version 7.0.1
    • php-mongodb version 1.1.1
      • Yes, 1.1.1 supports php7.

      其他可能有用的信息:

      • MongoDB版本3.2.0
      • mongod正在运行
      • 也尝试过重启,没有变化.
      • MongoDB Version 3.2.0
      • mongod is running
      • Also tried rebooting, no change.

      推荐答案

      好,我找到了答案.

      班级已更改.它不再是\MongoClient,现在是\MongoDB\Driver\Manager

      The class has been changed. It's no longer \MongoClient, and is now \MongoDB\Driver\Manager

      我所需要的只是一个重构.新的驱动程序被设计为低级驱动程序,用于将用户空间库填充为高级功能,因此,其他任何升级到php7的人,请确保您对新驱动程序或用户空间感到满意.库在您执行操作时就存在.希望这个问题/答案将来能对其他人有所帮助.

      All that I need is a refactor. The new driver is designed to be a lower-level driver for high-level functionality to be filled with userspace libraries, so anyone else upgrading to php7, make sure you check that you'll be comfortable with the new driver, or that the userspace libraries exist when you do it. Hopefully this question/answer helps others in the future.

      下面的注释者ianaz为MongoDB发布了这个很好的用户空间库: http://mongodb.github .io/mongo-php-library/

      Commenter ianaz below has posted this good userspace library for MongoDB: http://mongodb.github.io/mongo-php-library/

      这篇关于将PHP升级到版本7后,为什么不能使用mongodb驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆