summaryrefslogtreecommitdiffstats
path: root/zstd.php
diff options
context:
space:
mode:
Diffstat (limited to 'zstd.php')
-rw-r--r--zstd.php17
1 files changed, 10 insertions, 7 deletions
diff --git a/zstd.php b/zstd.php
index 0ec22d7..43d6d3f 100644
--- a/zstd.php
+++ b/zstd.php
@@ -12,6 +12,9 @@
if (PHP_VERSION_ID < 70400 || !extension_loaded("ffi")) {
die("PHP 7.4 with FFI required\n");
}
+if (PHP_SAPI != "cli") {
+ Header('Content-Type: text/plain');
+}
printf("PHP version %s\n", PHP_VERSION);
if (PHP_SAPI == "cli" && !class_exists("\\Remi\\Zstd")) {
@@ -27,20 +30,20 @@ if (class_exists("\\Remi\\Zstd")) {
$comp = \Remi\Zstd::compress($src);
printf("\nSrc length = %d\n", \strlen($src));
printf("ZSTD_compress = %d\n", \strlen($comp));
- file_put_contents("testffi.zstd", $comp);
+ file_put_contents("/tmp/testffi.zstd", $comp);
- $comp = file_get_contents("testffi.zstd");
+ $comp = file_get_contents("/tmp/testffi.zstd");
$out = \Remi\Zstd::decompress($comp);
printf("Src length = %d\n", \strlen($comp));
printf("ZSTD_decompress = %d\n", \strlen($out));
- file_put_contents("testffi.orig", $out);
+ file_put_contents("/tmp/testffi.orig", $out);
printf("Check = %s\n", $src === $out ? "OK" : "KO");
$t = microtime(true) - $t;
printf("Using FFI extension = %.3f\"\n\n", $t);
} else {
- printf("FFI missing\n\n");
+ printf("\\Remi\\Zstd missing\n\n");
}
if (extension_loaded("zstd")) {
@@ -53,14 +56,14 @@ if (extension_loaded("zstd")) {
$clen = strlen($comp);
printf("ZSTD_compress = %d\n", $clen);
$comp = substr($comp, 0, $clen);
- file_put_contents("testzstd.zstd", $comp);
+ file_put_contents("/tmp/testzstd.zstd", $comp);
- $comp = file_get_contents("testzstd.zstd");
+ $comp = file_get_contents("/tmp/testzstd.zstd");
printf("Src length = %d\n", \strlen($comp));
$unco = zstd_uncompress($comp);
$ulen = strlen($unco);
printf("ZSTD_decompress = %d\n", $ulen);
- file_put_contents("testzstd.orig", $unco);
+ file_put_contents("/tmp/testzstd.orig", $unco);
printf("Check = %s\n", $src === $unco ? "OK" : "KO");
$t = microtime(true) - $t;