gpt4 book ai didi

curl - 如何使用 curl 来比较页面的大小启用了 deflate 和不使用它

转载 作者:行者123 更新时间:2023-12-03 07:54:11 25 4
gpt4 key购买 nike

我有 mod_deflate 的 apache启用。我想用 mod_deflate 找出页面的大小启用和不启用,并比较在大小上实现了多少性能。在 curl 中,我似乎使用 --compressed 向服务器询问压缩后的内容并发送正常,但似乎无法找到该页面的大小。知道怎么做吗?
curl --head http://site

HTTP/1.1 200 OK
Date: Wed, 08 Feb 2012 08:48:04 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.7a mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By: PHP/5.2.12
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=ce39b051a9cd493cbe4a86056e11d61f; path=/
Vary: Accept-Encoding
Content-Type: text/html
curl --head --compressed http://site
HTTP/1.1 200 OK
Date: Wed, 08 Feb 2012 08:48:19 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.7a mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By: PHP/5.2.12
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=513b8ac5818fd043471c8aac44355898; path=/
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Content-Type: text/html

最佳答案

我认为获得大小的唯一可靠方法是实际下载文件。但是,curl 提供了一个非常方便的选项,用于仅输出感兴趣的数据

-w/--write-out <format>
Defines what to display on stdout after a completed and successful operation.

[...]

size_download The total amount of bytes that were downloaded.

这意味着你可以做这样的事情:
curl -so /dev/null http://www.whatsmyip.org/http-compression-test/ -w '%{size_download}'

输出:
8437

并获得压缩大小:
curl --compressed -so /dev/null http://www.whatsmyip.org/http-compression-test/ -w '%{size_download}'

输出:
3225

之后你的比较应该是微不足道的。

关于curl - 如何使用 curl 来比较页面的大小启用了 deflate 和不使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9190190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com