I’ve been wanting to try zookeeper for the past couple of days, and figured I’d level up a bit along the way. I looked up the official releases, 3.5.5 and 3.4.14. The PHP manual also explains how to configure it, though the extension hasn’t been updated in ages — I just gave it a try anyway.
I downloaded the php-zookeeper extension, dropped it locally, compiled and installed it. Every time I ran make it errored out about a missing lzookeeper_mt.so library.
The tutorials I found through official channels were all for old versions, saying the library is generated under src/c in the root directory of the project. But I’m using version 3.5.5, and there’s no such directory there at all.
According to the official docs, new versions come in a bin build and a source build, meaning the bin one is already compiled — you download it and just configure a cfg file to use it.
What I downloaded was the bin version, already compiled, so I downloaded the source version instead (zookeeper downloads). In 3.5.5, if you want to use the C client you have to compile and install the library, in zookeeper-client under the project root. How exactly to compile it — I had no clue. The official docs (zookeeper 3.5.5 manual) say this:

It looked really complicated, but once you sort it out it’s actually clear. Still, it cost me several days of grief.
First, run the ant compile_jute command in the zookeeper root directory, which generates a generated directory under zookeeper-client/zookeeper-client-c
Then, in zookeeper-client/zookeeper-client-c, run the command autoreconf -if. If it errors out at this point, it’s usually because autoconf, automake and libtool aren’t installed; once they are, run autoreconf -if again
Finally run ./configure –enable-debug — add –enable-debug if this is a development or test environment
Next, run make. Generally speaking, this is where it errors out1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24rc/zookeeper.c: In function ‘print_completion_queue’:
src/zookeeper.c:2542:5: error: null argument where non-null required (argument 1) [-Werror=nonnull]
fprintf(LOGSTREAM,"Completion queue: ","empty\n");
^~~~~~~
src/zookeeper.c:2542:23: error: too many arguments for format [-Werror=format-extra-args]
fprintf(LOGSTREAM,"Completion queue: ","empty\n");
^~~~~~~~~~~~~~~~~~~~
src/zookeeper.c:2550:9: error: null argument where non-null required (argument 1) [-Werror=nonnull]
fprintf(LOGSTREAM,"%d,",cptr->xid);
^~~~~~~
src/zookeeper.c:2553:5: error: null argument where non-null required (argument 1) [-Werror=nonnull]
fprintf(LOGSTREAM,"end\n");
^~~~~~~
src/zookeeper.c: In function ‘format_endpoint_info’:
src/zookeeper.c:4410:21: error: ‘%d’ directive writing between 1 and 5 bytes into a region of size between 0 and 127 [-Werror=format-overflow=]
sprintf(buf,"%s:%d",addrstr,ntohs(port));
^~
src/zookeeper.c:4410:17: note: directive argument in the range [0, 65535]
sprintf(buf,"%s:%d",addrstr,ntohs(port));
^~~~~~~
src/zookeeper.c:4410:5: note: ‘sprintf’ output between 3 and 134 bytes into a destination of size 128
sprintf(buf,"%s:%d",addrstr,ntohs(port));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

I got stuck here for a long while, and only found out by searching online that it’s because of a different gcc version at compile time. Mine was gcc 8.8 locally, so I switched to a centos7 system right away
After installing centos7 in docker, copying over the zookeeper source, configuring the jdk and installing make, vim and the other software, I walked through the steps above again and it generated fine. Then I copied the generated libraries (lib files, include files) into the local zookeeper directory
Compile the php-zookeeper extension and run it. Just point configure at the library directory and you’re done.
That’s it.
Here’s a copy of the source combined with the official one, with the compiled libraries: zookeeper3.5.5


