How to make Couchbase extension load on PHP 7.0 on Windows

I have wasted 1.5 days to make the current Couchbase SDK work on my Windows machine with WAMP and PHP 7.0.4 (x86 thread-safe - build date Mar 2 2016 14:40:59) and found a solution.

I have tried to install the Couchbase PHP extension from http://developer.couchbase.com/server/other-products/release-notes-archives/php-sdk by downloading the proper versions of the extensions, putting them in PHP/ext folders and adding extension=php_couchbase.dll to PHP.INI

At first the print_r(get_loaded_extensions()) instruction did NOT show the couchbase extension as loaded. It also didn’t show as loaded in php_info().

The PHP error log showed things like:

[18-Jul-2016 07:55:17 UTC] PHP Warning: PHP Startup: Unable to load dynamic library ‘c:/wamp/bin/php/php7.0.4/ext/php_couchbase.dll’ - The specified module could not be found.
in Unknown on line 0

There are 2 files: php_couchbase.dll and libcouchbase.dll

The php_couchbase.dll is the PHP extension, and it depends on libcouchbase.dll. Unfortunately, it does NOT know how to load the libcouchbase.dll from the location from where php_couchbase.dll itself is stored. This is a problem which could probably be fixed very easily by the extension developers.

The solution I found is to copy libcouchbase.dll to the c:\wamp\bin\apache\apache2.4.18\bin folder. This is probably the current directory into which Apache (and PHP) runs, and by moving libcouchbase.dll there, the php_couchbase.dll extension can find the DLL there, and loads properly.

After copying libcouchbase.dll to that folder, the couchbase extension works properly. The phpinfo() shows something like:

couchbase support: enabled
extension version: 2.2.0
libcouchbase runtime version: 2.6.1 (git: eb09707433013b742c0aa221e564ad73ba8a3708)
libcouchbase headers version: 2.6.1 (git: eb09707433013b742c0aa221e564ad73ba8a3708)

Also, all examples work, the CouchbaseCluster class can be instantiated, etc.

The Couchbase PHP extension developers should fix this. Even if it’s a minor problem, it is important because PHP is the most popular programming language for the web. Making Couchbase work with PHP (and other popular languages) without wasting days configuring it should be a top priority. Other databases such as MySQL and MS SQL Server do NOT require spending 2 days struggling to configure a simple PHP extension. This should work flawlessly.

@danarm do you use WAMP to deploy your production or for personal development needs?

@avsej - I am using WAMP on my development machine. When deploying, I plan to use IIS on Windows Server. I have not tested the CouchBase PHP extension on IIS yet.

The idea is that libcouchbase have to be in the PATH of executable, I thought that it is pretty common for windows. But this depends on the executable. We ship the extension, and cannot actually control the way how the executable loads its DLLs. The place depends on the type of executable and will be different for PHP.exe, apache2 or IIS, unless you put everything into the same directory or copy libcouchbase.dll into windows/system32 (and disable protection of system directory which removes all unknown DLLs)

@avsej - php_couchbase.dll loads libcouchbase.dll

In Windows API, this is done using a LoadLibrary function call. So php_couchbase.dll calls LoadLibrary to load libcouchbase.dll.

And in that call, it CAN extract the path where php_couchbase.dll itself is placed and specify the full path to libcouchbase.dll

I understand your idea with the PATH, but what I wrote above is good programming practice in Windows. It avoids something called “DLL hell” - where multiple programs load a DLL from the path and they require different versions of the DLL.

Also, if libcouchbase.dll needs to be placed in the path, the documentation should specify that. This doesn’t come to developers in a dream or as a revelation. :slight_smile: They have to read it in the documentation and this can save a lot of time.

We do not load libcouchbase explicitly from the extension code. And you are right about documentation. I will put there sentence about PATH

@avsej - thank you for updating the documentation. This means other developers won’t have to waste time, which is a win for everybody.