Skip to content

Instantly share code, notes, and snippets.

@bseddon
Last active January 14, 2023 15:35
Show Gist options
  • Save bseddon/7239a37a52ddd6d63afe587f9a4b89cc to your computer and use it in GitHub Desktop.
Save bseddon/7239a37a52ddd6d63afe587f9a4b89cc to your computer and use it in GitHub Desktop.

Building the PHP ZeroMQ extension (php-zmq) for Windows

Because there is no pre-compiled PHP ZMQ extension after PHP version 7.2 it's necessary to build your own. This is a short review of the process. The PHP ZMQ extension is a wrapper around libzmq which also needs to be built. The steps needed to build libzmq are covered in another gist.

Extensions are PHP version specific as the PHP internals vary from release to release. While it's not necessary to build PHP to build an extension an extension build requires some files from the build of a version of PHP. Because its not difficult to build PHP, why not? By building a version of PHP you can build the extension at the same time.

The steps needed to build PHP are listed in the PHP SDK GitHub repository. For the purposes of this page, after following the steps the working folder will be something like:

.\php-sdk\sdk\php-8.2\vs16\x64\php-src

Where 'php-sdk' is the folder of the first step and 'php-8.2' is the folder of the PHP version to be built. This folder will be referred to a php-src below.

Before you start, install Visual Studio 2019 (or the version that is required for the version being built) and with it, the VC++ packages. Make sure the VC++ package installs the CMake package and the tools.

After running

phpsdk_deps --update --branch master

and before running 'buildconf' the PHP ZMQ extension needs to be prepared.

  • Download the code zip for the PHP-ZMQ extension.
  • Unzip it into the folder 'php-src\ext\zmq'
  • The sub-folders 'examples', 'options', 'php5', 'tests', and 'travis' can be removed. The GitHub files can also be removed.
  • From the build of libzmq copy over 'libzmq.dll', 'libzmq.pdb' and 'libzmq-mt-gd-4_3_5.dll'.
  • From the build of libzmq copy over 'libzmq.lib' to the folder 'php-src\..\deps\lib'
  • From the build of libzmq copy over 'zmq.h' to the folder 'php-src\..\deps\include'

Now its back to the steps. After running 'buildconf' (while in the php-src folder) run:

configure --help

Scroll up the output list a bit where you should see an option '--with-zmq'. If this does not appear, something has gone wrong. Probably where the 'zmq' folder has been created or where the libzmq.lib or zmq.h files have been copied.

Assuming the option does appear its time to run configure. Here is my version of the command:

configure --enable-cli --disable-zts --with-bz2 --with-curl --with-dba --with-qdbm --with-db --with-lmdb --with-gettext --with-gmp --with-mhash --with-imap --enable-intl --enable-mbstring --enable-mbregex --with-openssl --with-pgsql --with-pspell --with-sodium --with-sqlite3 --with-zmq --with-mysqli

After running 'configure' run 'nmake'. This will compile PHP and the ZMQ extension. 'nmake' is a tool from the VC++ installation.

Finally run:

nmake snap

This will create the PHP package for deployment.

XDebug

Like extensions, XDebug versions are specific to the version of PHP with which it will be used. If the version of PHP being built is not the most recent then there is likely to be a compiled version of XDebug for the version you use. If not building it is straight forward. The basic instructions are on the XDebug site and the steps are pretty much the same as those for yum. The main difference is that the command is 'nmake' not 'make'.

To be able to build you will first need to run the commmand:

.\php-sdk\phpsdk-vc15-x64.bat

where 'php-sdk' is the folder created at the beginning the process to build PHP. This command will set up the environment for compilation.

Change the active folder of the command line so it is the folder into which the xdebug source has been saved.

'phpize' is a command shown in the xdebug build instructions. It's important this command is from the version of PHP with which XDebug will be used. If PHP has been built then this command will be in the folder:

.\php-sdk\sdk\php-8.2\vs16\x64\php-src\x64\Release\php-8.2.0-dev-devel-vs16-x64

where 'php-8.2' is the folder into which the PHP source was cloned and 'php-8.2.0' is the version of PHP that has been built.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment