1

I've build the Saxon/C PHP extension in a PHP-FPM docker image. The current extension name is ext-saxon/c, while PhpStorm and composer expect the extension name to be ext-saxonc. Is it possible to change/override that in either the Saxon build process or in PhpStorm?

enter image description here

When I use the code in PhpStorm, I get the following error:

enter image description here

To make PhpStorm aware of the Saxon extension, I have to manually enable it in the PHP Runtime settings, because it is not recognized automatically by the interpreter:

enter image description here

But now, I get the message that the ext-saxonc PHP extension is missing from my composer.json file.

enter image description here

In my composer.json file, I can do the following:

"require": {
    "ext-saxon/c": "*",
}

But I cannot do the below, because that extension is not recognized as installed.

"require": {
    "ext-saxonc": "*",
}

My docker code to build the extension:

FROM php:7.4.5-fpm

ARG saxon='libsaxon-HEC-setup64-v1.2.1'
RUN set -eux; \
    apt-get update && apt-get install -y --no-install-recommends wget; \
    cd /tmp && wget --quiet https://www.saxonica.com/saxon-c/${saxon}.zip; \
    unzip ${saxon}.zip; \
    ./${saxon} -batch -dest /tmp/saxon; \
    cp /tmp/saxon/libsaxonhec.so /usr/lib/; \
    cp -r /tmp/saxon/rt /usr/lib; \
    ldconfig; \
    cd /tmp/saxon/Saxon.C.API/; \
    phpize; \
    ./configure --enable-saxon; \
    make -j$(nproc); \
    make install; \
    docker-php-ext-enable saxon; \
    rm -rf /tmp/${saxon} /tmp/${saxon}.zip /tmp/saxon /var/lib/apt/lists/*;
kilar
  • 95
  • 2
  • 8
  • 1
    I am not able to answer this question directly but there is currently a hanging issue with Saxon/C on PHP. The patch for this is located here: https://saxonica.plan.io/attachments/48968 This relates to the bug issue: https://saxonica.plan.io/issues/4371 – ond1 Apr 24 '20 at 10:33
  • 1
    I also noticed that the version number is wrong (i.e. 1.2.0) I guess this is a bug. The new file has the version number corrected. I wonder if the extension name present in the function PHP_MINFO_FUNCTION has anything to `ext-saxon/c`? I suggest you could try changing it there to `saxonc`. – ond1 Apr 24 '20 at 10:37
  • Thank you for your comments. I tried your suggestion related to the `PHP_MIFO_FUNCTION`. The only thing that is changing (if you look at my `phpinfo()` screenshot above) is the dark purple header renamed from `Saxon/C` to `Saxon` (which is left from 'enabled' and one line above 'Saxon/C ext version'. This does not impact the `ext-saxon/c` naming. Screenshot: https://imgur.com/a/V48T2n4 – kilar Apr 25 '20 at 10:02
  • But if I change line 147 of `php_saxon.h` it does work! `#define PHP_SAXON_EXTNAME "Saxon/C"` => `#define PHP_SAXON_EXTNAME "SaxonC"`. I guess (didnt try) its also the case for the PHP5 version `php5_saxon.h`. As for my docker build, I added the following line between `phpize` and `./configure`: ``` sed -i 's/#define PHP_SAXON_EXTNAME "Saxon\/C"/#define PHP_SAXON_EXTNAME "SaxonC"/g' php_saxon.h; \ ``` – kilar Apr 25 '20 at 10:14
  • 1
    Great that you got it to work. We will look at this naming if this is something we should change too in the product. – ond1 Apr 25 '20 at 10:48
  • Great. This is what i found on PHP.net: `This "name" is an all-lowercase identifier containing only letters and underscores which is unique among everything in the ext/ folder of your PHP distribution. `. From: https://www.php.net/manual/en/internals2.buildsys.skeleton.php – kilar Apr 25 '20 at 21:54
  • Also. If I sync the PHP interpreter in PHPStorm the saxonc plugin is disabled. Which means PHPStorm still thinks its not installed. Maybe because its `saxon.so` and not `saxonc.so`? – kilar Apr 26 '20 at 20:14
  • 1
    I have created a bug issue for the naming bug: https://saxonica.plan.io/issues/4528 Bug now fixed. – ond1 Apr 27 '20 at 08:58
  • The patch php7_saxon.cpp has been updated here: https://saxonica.plan.io/attachments/48989 – ond1 May 12 '20 at 13:54

1 Answers1

1

Change line 147 of Saxon.C.API\php_saxon.h (or possibly Saxon.C.API\php5_saxon.h for PHP5) from:

#define PHP_SAXON_EXTNAME "Saxon/C"

to

#define PHP_SAXON_EXTNAME "SaxonC"

using

sed -i 's/#define PHP_SAXON_EXTNAME  "Saxon\/C"/#define PHP_SAXON_EXTNAME  "SaxonC"/g' php_saxon.h; \

New docker code:

FROM php:7.4.5-fpm

ARG saxon='libsaxon-HEC-setup64-v1.2.1'
RUN set -eux; \
    apt-get update && apt-get install -y --no-install-recommends wget; \
    cd /tmp && wget --quiet https://www.saxonica.com/saxon-c/${saxon}.zip; \
    unzip ${saxon}.zip; \
    ./${saxon} -batch -dest /tmp/saxon; \
    cp /tmp/saxon/libsaxonhec.so /usr/lib/; \
    cp -r /tmp/saxon/rt /usr/lib; \
    ldconfig; \
    cd /tmp/saxon/Saxon.C.API/; \
    sed -i 's/#define PHP_SAXON_EXTNAME  "Saxon\/C"/#define PHP_SAXON_EXTNAME  "saxonc"/g' php_saxon.h; \
    phpize; \
    ./configure --enable-saxon; \
    make -j$(nproc); \
    make install; \
    docker-php-ext-enable saxon; \
    rm -rf /tmp/${saxon} /tmp/${saxon}.zip /tmp/saxon /var/lib/apt/lists/*;
kilar
  • 95
  • 2
  • 8