简体   繁体   English

减少 cURL PHP 中的带宽使用

[英]Reduce Bandwidth usage in cURL PHP

I'm using basic cURL requests to fetch webpages in PHP, however these webpages are big in size and I'm limited in bandwidth usage.我正在使用基本的 cURL 请求来获取 PHP 中的网页,但是这些网页很大,而且我的带宽使用受到限制。

Is there a way to reduce/optimize cURL data usage, for example using compression.有没有办法减少/优化 cURL 数据使用,例如使用压缩。 I also heard that Brotli compression is the best, but I'm not sure how to use it.我还听说 Brotli 压缩是最好的,但我不知道如何使用它。

$headers[] = "Accept-Encoding: gzip"; // tell the server you accept gzip
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch,CURLOPT_ENCODING , "gzip"); // tells curl to gunzip it automatically
$data = curl_exec($ch);

Not tried this with brotli, support will vary by software version which you didn't tell us about.没有用 brotli 尝试过,支持会因您没有告诉我们的软件版本而异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM