diff options
author | Remi Collet <remi@remirepo.net> | 2019-10-24 09:21:52 +0200 |
---|---|---|
committer | Remi Collet <remi@remirepo.net> | 2019-10-24 09:21:52 +0200 |
commit | 47cb18001f6777b2c149c819497a3e8ed7edca81 (patch) | |
tree | 7e81bd7a54e09aa7adb497c41c0efef35804813f /zstd.php | |
parent | 261032f77820d0b620707ace75cfa82043558581 (diff) |
cleanup for web env
Diffstat (limited to 'zstd.php')
-rw-r--r-- | zstd.php | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -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; |