curl_setopt 设立过多,会不会有影响

WBOY
Release: 2016-06-13 12:59:10
Original
823 people have browsed it

curl_setopt 设置过多,会不会有影响?

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, gzip);
curl_close($ch);
Copy after login


curl抓取网站,某些网站用gzip压缩,需要设置CURLOPT_ENCODING才能正常显示,否则乱码。
请问:设置CURLOPT_ENCODING,会不会影响非gzip压缩的网站?(一个CLASS,是通用代码。)
另外,除了CURLOPT_RETURNTRANSFER,和CURLOPT_ENCODING,还有哪些curl_setopt设置使通常curl抓取网站需要注意使用的?谢谢。
------解决方案--------------------
多了,你去curl官网下个文档,就知道有几十个参数呢,当然不是一次全部用上的

压缩不影响的,是检测到双方都有这个参数才会自动调用的
------解决方案--------------------
curl_setopt 用于设置 curl 的工作参数
无论你是否设置,这些参数都是存在的。都将在运行时影响 curl 的行为
只不过你没设置,他就是用默认值而已

在默认情况下,只需 CURLOPT_URL 就可以了

如果你不想让 curl_exec 直接输出结果,而是返回给变量。那么就要设置 CURLOPT_RETURNTRANSFER,当然这是要消耗内存的
你需要自动解压 gzip 就得设置 CURLOPT_ENCODING,虽然对于非 gzip 他也要判断一下

这就是说,你要达到预期的目的,就要花费一定的代价

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!