Git Product home page Git Product logo

php-ext-zstd's Introduction

Zstd Extension for PHP

Linux Windows

This extension allows Zstandard.

Documentation for Zstandard can be found at » https://github.com/facebook/zstd.

Build from sources

% git clone --recursive --depth=1 https://github.com/kjdev/php-ext-zstd.git
% cd php-ext-zstd
% phpize
% ./configure
% make
% make install

To use the system library

% ./configure --with-libzstd

Install from pecl:

% pecl install zstd

Distribution binary packages

Fedora

Fedora users can install the » php-zstd package from official repository.

dnf install php-zstd

CentOS / RHEL

CentOS / RHEL (and other clones) users can install the » php-zstd package from » EPEL repository.

yum install php-zstd

Other RPM packages of this extension, for other PHP versions, are available in » Remi's RPM repository.

Configration

php.ini:

extension=zstd.so

Constant

Name Description
ZSTD_COMPRESS_LEVEL_MIN Minimal compress level value
ZSTD_COMPRESS_LEVEL_MAX Maximal compress level value
ZSTD_COMPRESS_LEVEL_DEFAULT Default compress level value
LIBZSTD_VERSION_NUMBER libzstd version number
LIBZSTD_VERSION_STRING libzstd version string

Function

  • zstd_compress — Zstandard compression
  • zstd_uncompress — Zstandard decompression
  • zstd_compress_dict — Zstandard compression using a digested dictionary
  • zstd_uncompress_dict — Zstandard decompression using a digested dictionary

zstd_compress — Zstandard compression

Description

string zstd_compress ( string $data [, int $level = 3 ] )

Zstandard compression.

Parameters

  • data

    The string to compress.

  • level

    The level of compression (1-22). (Defaults to 3)

    A value smaller than 0 means a faster compression level. (Zstandard library 1.3.4 or later)

Return Values

Returns the compressed data or FALSE if an error occurred.

zstd_uncompress — Zstandard decompression

Description

string zstd_uncompress ( string $data )

Zstandard decompression.

Alias: zstd_decompress

Parameters

  • data

    The compressed string.

Return Values

Returns the decompressed data or FALSE if an error occurred.

zstd_compress_dict — Zstandard compression using a digested dictionary

Description

string zstd_compress_dict ( string $data , string $dict [, int $level = 3 ])

Zstandard compression using a digested dictionary.

Alias: zstd_compress_usingcdict

Parameters

  • data

    The string to compress.

  • dict

    The Dictionary data.

  • level

    The level of compression (1-22). (Defaults to 3)

Return Values

Returns the compressed data or FALSE if an error occurred.

zstd_uncompress_dict — Zstandard decompression using a digested dictionary

Description

string zstd_uncompress_dict ( string $data , string $dict )

Zstandard decompression using a digested dictionary.

Alias: zstd_decompress_dict, zstd_uncompress_usingcdict, zstd_decompress_usingcdict

Parameters

  • data

    The compressed string.

  • dict

    The Dictionary data.

Return Values

Returns the decompressed data or FALSE if an error occurred.

Namespace

Namespace Zstd;

function compress( $data [, $level = 3 ] )
function uncompress( $data )
function compress_dict ( $data, $dict )
function uncompress_dict ( $data, $dict )

zstd_compress, zstd_uncompress, zstd_compress_dict and zstd_uncompress_dict function alias.

Streams

Zstd compression and decompression are available using the compress.zstd:// stream prefix.

Examples

// Using functions
$data = zstd_compress('test');
zstd_uncompress($data);

// Using namespaced functions
$data = \Zstd\compress('test');
\Zstd\uncompress($data);

// Using streams
file_put_contents("compress.zstd:///path/to/data.zstd", $data);
readfile("compress.zstd:///path/to/data.zstd");

// Providing level of compression, when using streams 
$context = stream_context_create([
    'zstd' => [
            'level' => ZSTD_COMPRESS_LEVEL_MIN,
        ],
    ],
);

file_put_contents("compress.zstd:///path/to/data.zstd", $data, context: $context);
readfile("compress.zstd:///path/to/data.zstd", context: $context);

php-ext-zstd's People

Contributors

berezuev avatar cmb69 avatar dariuskasiulevicius avatar demonjr avatar dixyes avatar fedotov-as avatar glensc avatar jakubonderka avatar kjdev avatar martinml avatar nobuf avatar remicollet avatar romulasry avatar sergey-dryabzhinsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-ext-zstd's Issues

Documenting APCu support

Hi, I maintain the PHP ports in MacPorts and I just discovered that the zstd extension will check for the presence of the APCu extension at build time:

php-ext-zstd/config.m4

Lines 105 to 112 in 0bf5825

AC_MSG_CHECKING([for APCu includes])
if test -f "$phpincludedir/ext/apcu/apc_serializer.h"; then
apc_inc_path="$phpincludedir"
AC_MSG_RESULT([APCu in $apc_inc_path])
AC_DEFINE(HAVE_APCU_SUPPORT, 1, [Whether to enable APCu support])
else
AC_MSG_RESULT([not found])
fi

Now I have to decide how I should handle this in MacPorts and I didn't find any documentation about what the zstd extension does with APCu so I wanted to ask here if you could answer some questions or maybe document it.

What does the zstd extension do if it finds APCu at build time? How does it use it?

If the zstd extension finds APCu at build time, does it require it to be present at runtime? This would dictate whether I give the php-zstd port a dependency on the php-APCu port that is only needed at build time or also at runtime.

When the APCu code was first added to the zstd extension in 45c876a, the check for APCu in config.m4 was unconditional but all the uses of APCu-related code were guarded by PHP_MAJOR_VERSION >= 7. At that time the zstd extension still supported PHP 5. I believe the last version of the zstd extension that supported PHP 5 was 0.11.1 and the last version of APCu to do so was 4.0.11. If I have that version of APCu installed while building that version of the zstd extension with PHP 5, am I correct in assuming that it will find APCu at configure time but will do nothing with it at build time and that therefore no APCu dependency of any kind should be added for the PHP 5 case?

Thanks.

Missing zstd_getFrameContentSize() function

Currently, the PHP extension for Zstandard (zstd) is missing the ZSTD_getFrameContentSize function, which is available in the underlying Zstandard library. This function is not only useful for determining the size of the original uncompressed data in a Zstandard-compressed frame but also for reliably whether the data is indeed compressed with Zstandard.

This could be added to help developers avoid errors like these, (during odd circumstances)
Warning: zstd_uncompress(): it was not compressed by zstd

Adding it would not only allow developers to determine the size of the original uncompressed data but also reliably detect whether the data is compressed with Zstandard, enhancing the usability and versatility of the PHP extension.

Version Info

PHP Version: 8.3.3
Extension Version | 0.13.1
Interface Version | 1.5.4

Thank you for your attention to this matter.

Missing new test in pecl archive

Hi,

New test (tests/streams_9.phpt) is missing in pecl archive
but I don't find package.xml in the git repository, so cannot open a PR on it

Error compiling PHP8.2 snap

Compilinig PHP 8.2 with extension apcu and zstd i get error:

ext\zstd\zstd.c(903): error C2036: 'void *': unknown size

If i remove apcu extension everything is fine.

Also i tried to compile zstd extension static and shared with apcu extension enabled and same error.

Error when building for PHP 8.2 on Debian Buster with system lib

Does not compile with the following error:

159.0 2: /tmp/zstd/zstd-0.13.1/zstd.c: In function 'php_zstd_comp_write':
159.0 2: /tmp/zstd/zstd-0.13.1/zstd.c:626:13: error: 'ret' undeclared (first use in this function); did you mean 'res'?
159.0 2:              ret += count;
159.0 2:              ^~~
159.0 2:              res

I guess it's a typo in the variable name?

Add a function or constant that gets maxLevel

Hello @kjdev I encountered a problem when I used the zstd_compress function. I don't know how to enter the value of the level. I read the source code and found that the level should be filled with level > maxLevel but maxLevel is obtained by ZSTD_maxCLevel. Can you add a new function or constant to get the value of maxLevel?

Use Zstd version string / function for phpInfo

Not sure when it appeared in zstd:

// php_info_print_table_row(2, "Interface Version", buffer);
php_info_print_table_row(2, "Interface Version", ZSTD_versionString());
// or
php_info_print_table_row(2, "Interface Version", ZSTD_VERSION_STRING);

New tagged release with Zstd 1.5.2

Zstd submodule has been updated from 1.5.0 to 1.5.2 in the master branch but there has not been an associated release, could there possibly be one to allow removing dependency on a branch/commit for the improvements?

Chrome finally ships Accept-Encoding: zstd — Please update example

Hi and late Happy Easter all!

As the title suggests, no issue in the buggy sense.

I ran some benchmarks against a 4 MB HTML file:

  # none......:  4,039,229 Bytes;  100 requests in   3.16 secs  (avg=0.0316 s per req)
  # gzip......:  1,290,963 Bytes;  100 requests in  17.65 secs  (avg=0.1765 s per req)
  # obgz......:  1,290,963 Bytes;  100 requests in  17.27 secs  (avg=0.1727 s per req)
  # zstd1.....:  1,392,549 Bytes;  100 requests in   4.01 secs  (avg=0.0401 s per req)
  # zstd2.....:  1,310,025 Bytes;  100 requests in   4.32 secs  (avg=0.0432 s per req)
  # zstd3.....:  1,240,800 Bytes;  100 requests in   4.45 secs  (avg=0.0445 s per req)
  # zstd4.....:  1,222,309 Bytes;  100 requests in   4.76 secs  (avg=0.0476 s per req)
  # zstd5.....:  1,195,749 Bytes;  100 requests in   5.84 secs  (avg=0.0584 s per req)
  # zstd6.....:  1,157,140 Bytes;  100 requests in   6.94 secs  (avg=0.0694 s per req)
  # zstd7.....:  1,133,898 Bytes;  100 requests in   8.18 secs  (avg=0.0818 s per req)
  # zstd8.....:  1,120,307 Bytes;  100 requests in   9.71 secs  (avg=0.0971 s per req)
  # zstd9.....:  1,115,600 Bytes;  100 requests in   9.80 secs  (avg=0.0980 s per req)
  # zstd10....:  1,095,873 Bytes;  100 requests in  12.33 secs  (avg=0.1233 s per req)
  # zstd11....:  1,082,522 Bytes;  100 requests in  18.20 secs  (avg=0.1820 s per req)
  # zstd12....:  1,081,317 Bytes;  100 requests in  21.91 secs  (avg=0.2191 s per req)
  # zstd13....:  1,059,720 Bytes;  100 requests in  52.40 secs  (avg=0.5240 s per req)
  # zstd14....:  1,044,099 Bytes;  100 requests in  67.91 secs  (avg=0.6791 s per req)
  # zstd15....:  1,036,078 Bytes;  100 requests in  87.37 secs  (avg=0.8737 s per req)
  # zstd16....:    983,006 Bytes;  100 requests in 103.78 secs  (avg=1.0378 s per req)
  # zstd17....:    980,923 Bytes;  100 requests in 115.09 secs  (avg=1.1509 s per req)
  # zstd18....:    972,316 Bytes;  100 requests in 141.62 secs  (avg=1.4162 s per req)
  # zstd19....:    971,972 Bytes;  100 requests in 145.05 secs  (avg=1.4505 s per req)
  # zstd20....:    971,972 Bytes;  100 requests in 146.45 secs  (avg=1.4645 s per req)
  # zstd21....:    971,972 Bytes;  100 requests in 148.13 secs  (avg=1.4813 s per req)
  # zstd22....:    971,962 Bytes;  100 requests in 152.34 secs  (avg=1.5234 s per req)

Kindly suggest updating your README's example section to include output buffering:

# Serve ZSTD compressed PHP pages to modern 2024 web browsers:
# Place this snippet *before* any of your HTML output begins.
if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'zstd')) {
    header("Content-Encoding: zstd");
    ob_start(function(&$data) {
        return zstd_compress($data, 3); # level 3 is default, max. and slowest is 22
    });
} else {
    ob_start('ob_gzhandler'); # fallback for older browsers
}

Perhaps @remicollet could put some soft pressure on the PHP core team to bundle this extension? 🚀

Thanks!

compilation does not handle with-libdir correctly

/usr/local is added:
./configure --host=x86_64-mageia-linux-gnu --build=x86_64-mageia-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-libzstd --with-libdir=lib64 --enable-zstd=shared,/usr

results in
cc -shared -Wl,--as-needed .libs/zstd.o -Wl,--as-needed -Wl,-z -Wl,relro -Wl,-O1 -Wl,--build-id=sha1 -Wl,--enable-new-dtags -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib -lzstd -Wl,-soname -Wl,zstd.so -o .libs/zstd.so creating zstd.la

and should be /usr/lib64.

Is an "ob_zstdhandler" function possible?

Hi!

Firstly congratulations, this a great extension (as well as your others).

I was wondering if you think it could be possible to have an ob_zstdhandler function similar to the ob_gzhandler?

zstd_compress works great with ob_start, but only if the whole page is compressed at once.

If we set a chunk_size when calling ob_start, or if we call ob_flush before ob_end_flush, we can't use zstd_compress.

Using chunk_size or/and ob_flush allows to send data early, so the client can start rendering the page, without having to wait for the entire page to be generated server side.

If this is possible, I think it would be a terrific feature.

Regards,

Edit: I don't know if my question is related to this request Support incremental compression and decompression.

Add PHP 8.0 DLLs on PECL

Currently the Windows DLLs on PECL repo are 7.2. to 7.4. Add PHP 8.0 please since it's now stable.

Few warnings on 32-bit arches

Used to build new 0.13.0 release and faced on armv7,x86 following

/bin/sh /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/libtool --mode=compile gcc -I. -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0 -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/include -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/main -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0 -I/usr/include/php82 -I/usr/include/php82/main -I/usr/include/php82/TSRM -I/usr/include/php82/Zend -I/usr/include/php82/ext -I/usr/include/php82/ext/date/lib  -DHAVE_CONFIG_H  -Os -fstack-clash-protection -Wformat -Werror=format-security -D_GNU_SOURCE    -DZEND_COMPILE_DL_EXT=1 -c /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/zstd.c -o zstd.lo  -MMD -MF zstd.dep -MT zstd.lo
mkdir .libs
 gcc -I. -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0 -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/include -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/main -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0 -I/usr/include/php82 -I/usr/include/php82/main -I/usr/include/php82/TSRM -I/usr/include/php82/Zend -I/usr/include/php82/ext -I/usr/include/php82/ext/date/lib -DHAVE_CONFIG_H -Os -fstack-clash-protection -Wformat -Werror=format-security -D_GNU_SOURCE -DZEND_COMPILE_DL_EXT=1 -c /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/zstd.c -MMD -MF zstd.dep -MT zstd.lo  -fPIC -DPIC -o .libs/zstd.o
In file included from /usr/include/php82/Zend/zend_types.h:25,
                 from /usr/include/php82/Zend/zend.h:27,
                 from /usr/include/php82/main/php.h:31,
                 from /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/zstd.c:28:
/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/zstd.c: In function 'zif_zstd_compress':
/usr/include/php82/Zend/zend_API.h:1767:59: warning: passing argument 2 of 'zend_parse_arg_long' from incompatible pointer type [-Wincompatible-pointer-types]
 1767 |                 if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, _i))) { \
/usr/include/php82/Zend/zend_portability.h:364:52: note: in definition of macro 'UNEXPECTED'
  364 | # define UNEXPECTED(condition) __builtin_expect(!!(condition), 0)
      |                                                    ^~~~~~~~~
/usr/include/php82/Zend/zend_API.h:1774:9: note: in expansion of macro 'Z_PARAM_LONG_EX'
 1774 |         Z_PARAM_LONG_EX(dest, _dummy, 0, 0)
      |         ^~~~~~~~~~~~~~~
/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/zstd.c:145:9: note: in expansion of macro 'Z_PARAM_LONG'
  145 |         Z_PARAM_LONG(level)
      |         ^~~~~~~~~~~~
In file included from /usr/include/php82/main/php.h:35:
/usr/include/php82/Zend/zend_API.h:2068:74: note: expected 'zend_long *' {aka 'int *'} but argument is of type 'long int *'
 2068 | static zend_always_inline bool zend_parse_arg_long(zval *arg, zend_long *dest, bool *is_null, bool check_null, uint32_t arg_num)
      |                                                               ~~~~~~~~~~~^~~~
/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/zstd.c: In function 'zif_zstd_compress_dict':
/usr/include/php82/Zend/zend_API.h:1767:59: warning: passing argument 2 of 'zend_parse_arg_long' from incompatible pointer type [-Wincompatible-pointer-types]
 1767 |                 if (UNEXPECTED(!zend_parse_arg_long(_arg, &dest, &is_null, check_null, _i))) { \
/usr/include/php82/Zend/zend_portability.h:364:52: note: in definition of macro 'UNEXPECTED'
  364 | # define UNEXPECTED(condition) __builtin_expect(!!(condition), 0)
      |                                                    ^~~~~~~~~
/usr/include/php82/Zend/zend_API.h:1774:9: note: in expansion of macro 'Z_PARAM_LONG_EX'
 1774 |         Z_PARAM_LONG_EX(dest, _dummy, 0, 0)
      |         ^~~~~~~~~~~~~~~
/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/zstd.c:287:9: note: in expansion of macro 'Z_PARAM_LONG'
  287 |         Z_PARAM_LONG(level)
      |         ^~~~~~~~~~~~
/usr/include/php82/Zend/zend_API.h:2068:74: note: expected 'zend_long *' {aka 'int *'} but argument is of type 'long int *'
 2068 | static zend_always_inline bool zend_parse_arg_long(zval *arg, zend_long *dest, bool *is_null, bool check_null, uint32_t arg_num)
      |                                                               ~~~~~~~~~~~^~~~
/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/zstd.c: In function 'zstd_apc_unserializer':
/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/zstd.c:908:45: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'int' [-Wformat=]
  908 |                          "Error at offset %ld of %ld bytes",
      |                                           ~~^
      |                                             |
      |                                             long int
      |                                           %d
  909 |                          (zend_long) (tmp - (unsigned char*) var),
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                          |
      |                          int
/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/zstd.c:908:52: warning: format '%ld' expects argument of type 'long int', but argument 5 has type 'int' [-Wformat=]
  908 |                          "Error at offset %ld of %ld bytes",
      |                                                  ~~^
      |                                                    |
      |                                                    long int
      |                                                  %d
  909 |                          (zend_long) (tmp - (unsigned char*) var),
  910 |                          (zend_long) var_len);
      |                          ~~~~~~~~~~~~~~~~~~~        
      |                          |
      |                          int
/bin/sh /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/libtool --mode=link gcc -shared -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/include -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/main -I/builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0 -I/usr/include/php82 -I/usr/include/php82/main -I/usr/include/php82/TSRM -I/usr/include/php82/Zend -I/usr/include/php82/ext -I/usr/include/php82/ext/date/lib  -DHAVE_CONFIG_H  -Os -fstack-clash-protection -Wformat -Werror=format-security -D_GNU_SOURCE  -Wl,--as-needed,-O1,--sort-common -Wl,-z,pack-relative-relocs  -o zstd.la -export-dynamic -avoid-version -prefer-pic -module -rpath /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/modules  zstd.lo -lzstd
gcc -shared  .libs/zstd.o  -lzstd  -Wl,--as-needed -Wl,-O1 -Wl,--sort-common -Wl,-z -Wl,pack-relative-relocs -Wl,-soname -Wl,zstd.so -o .libs/zstd.so
creating zstd.la
(cd .libs && rm -f zstd.la && ln -s ../zstd.la zstd.la)
/bin/sh /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/libtool --mode=install cp ./zstd.la /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/modules
cp ./.libs/zstd.so /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/modules/zstd.so
cp ./.libs/zstd.lai /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/modules/zstd.la
PATH="$PATH:/sbin" ldconfig -n /builds/alpine/aports/community/php82-pecl-zstd/src/zstd-0.13.0/modules

refs (available 7 days)

Dangerous reloaction

When compiling from source using system library, upon make, I get this fatal error:

/usr/lib/gcc/aarch64-linux-gnu/12/../../../aarch64-linux-gnu/libzstd.a(zstd_compress.o): in function `ZSTD_compressSequences':
zstd_compress.c:(.text+0x10abc): dangerous relocation: unsupported relocation
/usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/12/../../../aarch64-linux-gnu/libzstd.a(zstd_compress.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `ZSTD_copySequencesToSeqStoreNoBlockDelim' which may bind externally can not be used when making a shared object; recompile with -fPIC
zstd_compress.c:(.text+0x10c64): dangerous relocation: unsupported relocation
/usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/12/../../../aarch64-linux-gnu/libzstd.a(zstd_compress.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `ZSTD_copySequencesToSeqStoreExplicitBlockDelim' which may bind externally can not be used when making a shared object; recompile with -fPIC
zstd_compress.c:(.text+0x10c78): dangerous relocation: unsupported relocation
/usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/12/../../../aarch64-linux-gnu/libzstd.a(zstd_compress.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `ZSTD_copySequencesToSeqStoreExplicitBlockDelim' which may bind externally can not be used when making a shared object; recompile with -fPIC
zstd_compress.c:(.text+0x1116c): dangerous relocation: unsupported relocation
collect2: error: ld returned 1 exit status
make: *** [Makefile:215: zstd.la] Error 1

zstd_compress_dict can not set compression level

It seems impossible to use a dictionary and set the compression to a high level.
I did some tested with the zstd cli version. Using zstd cli with a dictionary and the max level the end result is about 30% smaller, than with the default level.

I hope you can support setting the compression level for the dictionary. Thanks.

Decompression from File Handler

I found out that is impossible to decompress form a file handler reading chunks.

I have a very big file that have compressed data starting from an offset.
i have a file handler and seek to the start of compressed data
it will be very very useful for me (and for many others i think) a function that can get the file handler and read chunks of data outputing the uncompressed data

like

$this->fh = fopen("FILE",'r');
fseek($this->fh,$this->offset); //the start of compressed data

$zstd_object = zstd_uncompress_handler($this->fh);

while(EOF or some condition){
$outdata = $zstd_object->uncompress($chunksize); //just an idea of object function
// Data here can be printed or anything else (for a on the fly download and so on)
}

This can be done and you think can be usefull? (if so i'll use for sure on my project)

zstd on windows

Hi
I modified php.ini as following but i can not see zstd in phpinfo.php report. How can be sure extension is enabled?
php_zstd.dll NTS placed in C:\Program Files\PHP\v7.4.24\ext

[PHP_Zstandard]
zend_extension=php_zstd.dll

config.w32 compile failed on 0.12.1

Hi @kjdev,
Thanks for 0.12.1!
config.w32 change (65c431a) failed on compile as PHP_DIR is undefined.
Here is my quick working patch which correspond to a standard use of CHECK_HEADER_ADD_INCLUDE using PHP_ZSTD

diff --git "a/config.w32" "b/config.w32"
index 17922bf..c54c9ed 100644
--- "a/config.w32"
+++ "b/config.w32"
@@ -1,7 +1,7 @@
 ARG_ENABLE("zstd", "zstd support", "yes");
 
 if (PHP_ZSTD != "no") {
-  if (CHECK_HEADER_ADD_INCLUDE("ext/apcu/apc_serializer.h", "CFLAGS_ZSTD", PHP_DIR + "\\include")) {
+  if (CHECK_HEADER_ADD_INCLUDE("ext/apcu/apc_serializer.h", "CFLAGS_ZSTD", PHP_ZSTD)) {
     AC_DEFINE("HAVE_APCU_SUPPORT", 1, "APCu support");
   }

Warning: zstd_compress: compression level (100) must be within 1..22 or smaller then 0

For me this test fails for php 5.3-5.6, 7.0-7.3, passes on 7.4

TEST 10/24 [tests/008.phpt]
========DIFF========
028+ Warning: zstd_compress: compression level (100) must be within 1..22 or smaller then 0 in /tmp/B.lZPARi/BUILD/php73-pecl-zstd-0.8.0/tests/008.php on line 6
029+ 100 -- 0 --
030+ Warning: zstd_uncompress: it was not compressed by zstd in /tmp/B.lZPARi/BUILD/php73-pecl-zstd-0.8.0/tests/008.php on line 8
031+ false
032+ -1 -- 2674 -- true
033+ 0 -- 3547 --
034+ Warning: zstd_uncompress: it was not compressed by zstd in /tmp/B.lZPARi/BUILD/php73-pecl-zstd-0.8.0/tests/008.php on line 8
035+ false
028- Warning: zstd_compress: compression level (100) must be within 1..22 in %s on line %d
029- 100 -- 0 -- false
030-
031- Warning: zstd_compress: compression level (-1) must be within 1..22 in %s on line %d
032- -1 -- 0 -- false
033- 0 -- 3547 -- false

Build logs:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.