MacOS 上的 Cassandra php 驱动程序 - 找不到“Cassandra\SimpleStatement”类

ANT*_*GEO 1 php macos cassandra datastax datastax-php-driver

今天是个好日子。

通常我只是在 *nix OS 中使用这个官方文档

但是现在我正在使用 MacO,而此说明无法正常工作。

如果pecl install cassandra我收到此消息:

checking for supported DataStax C/C++ driver version... awk: can't open file /include/cassandra.h
 source line number 1
configure: error: not supported. Driver version 2.4.2+ required (found )
ERROR: `/private/tmp/pear/install/cassandra/configure --with-php-config=/usr/bin/php-config' failed
Run Code Online (Sandbox Code Playgroud)

我的逻辑告诉我,在这种情况下,我需要自己制作 DataStax C/C++ 驱动程序。在文件夹中,php-driver\lib我删除cpp-driver并使用此指令制作全新的 C/C++ 驱动程序,没有错误。

所以在官方文档中它说:

注意 install.sh 脚本还将编译并静态链接到扩展中的一个用于 Apache Cassandra 的 DataStax C/C++ 驱动程序的子模块版本。要使用系统上已有的 cpp 驱动程序版本,请运行 phpize、./configure 并进行安装。

但是当我尝试运行时./configurephp-drive/ext我得到了几乎相同的错误:

checking for supported DataStax C/C++ driver version... awk: can't open file /include/cassandra.h
 source line number 1
configure: error: not supported. Driver version 2.4.2+ required (found )
Run Code Online (Sandbox Code Playgroud)

即使我继续并在该错误运行之后make install它也会给我该日志:

/bin/sh /Users/antvirgeo/php-driver/ext/libtool --mode=install cp ./cassandra.la /Users/antvirgeo/php-driver/ext/modules
cp ./.libs/cassandra.so /Users/antvirgeo/php-driver/ext/modules/cassandra.so
cp ./.libs/cassandra.lai /Users/antvirgeo/php-driver/ext/modules/cassandra.la
----------------------------------------------------------------------
Libraries have been installed in:
   /Users/antvirgeo/php-driver/ext/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20121212/
cp: /usr/lib/php/extensions/no-debug-non-zts-20121212/#INST@24727#: Operation not permitted
make: *** [install-modules] Error 1
Run Code Online (Sandbox Code Playgroud)

库已安装在:
/Users/antvirgeo/php-driver/ext/modules

即使我将带有该路径的 cassandra 扩展添加到 php.iniClass 'Cassandra\SimpleStatement' not found我的项目中仍然出现错误。

php -d="extension=modules/cassandra.so" -m显示cassandra在 PHP 模块列表中

我究竟做错了什么?

PS:我在 Parallels 中安装了 ubuntu 操作系统,该项目安装了 DataStax php 驱动程序,并按照此说明正常工作。

____upd:在没有任何错误的@Fero 的所有指令之后,命令/usr/local/bin/php -i | grep -A 10 "^cassandra$"向我展示了这个:

cassandra

Cassandra support => enabled
C/C++ driver version => 2.4.2
Persistent Clusters => 0
Persistent Sessions => 0

Directive => Local Value => Master Value
cassandra.log => cassandra.log => cassandra.log
cassandra.log_level => ERROR => ERROR
Run Code Online (Sandbox Code Playgroud)

仍然是同样的错误 - Class 'Cassandra\SimpleStatement' not found

______________最后更新:

Aaaaand它的工作!我phpinfo();在我的项目中写了输出,并意识到使用其他 php 版本的 apache 和php.ini,根本没有extension=cassandra.so

小智 5

您将需要安装 DataStax C/C++ 驱动程序,它是 PHP 驱动程序的依赖项。使用这些指令,然后make install后的驱动程序已经成功建立将确保这种依赖关系构建PHP驱动程序时可用。使用 PHP 驱动程序构建说明,您需要确保 GMP 和 PHP 开发库在运行之前也可用pecl install cassandra

编辑:

由于您使用的是 El Capitan ,您会遇到系统完整性保护问题,您需要禁用它才能将文件复制到/usr. 更好的推荐选项是使用Homebrew安装 PHP ;但是,如果愿意,您也可以使用MacPorts

以下是用于在已安装 Xcode 和 Homebrew 的干净 OSX El Capitan 映像上重现 PHP 驱动程序安装的步骤:

brew install autoconf cmake libuv gmp openssl pcre homebrew/php/php55
brew link homebrew/php/php55
mkdir code
pushd code
git clone https://github.com/datastax/php-driver.git
pushd php-driver
git submodule update --init --recursive
pushd lib/cpp-driver
mkdir build
pushd build
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl ..
make -j$(sysctl -n hw.ncpu)
sudo make install
popd
popd
mkdir build
pushd ext
/usr/local/bin/phpize
popd
pushd build
../ext/configure --with-php-config=/usr/local/bin/php-config
make -j$(sysctl -n hw.ncpu)
sudo make install
popd
popd
sudo sh -c 'echo "extension=cassandra.so" >> /usr/local/etc/php/5.5/php.ini'
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用以下命令验证安装:

/usr/local/bin/php -i | grep -A 10 "^cassandra$"
Run Code Online (Sandbox Code Playgroud)

注意:上面使用的是 PHP v5.5,因为它是 El Capitan 附带的默认版本;也可以使用 PHP v5.6 和 v7.0。