[英]Getting the cURL stream in PHP
If I run curl_exec
with no options, the fetched page gets output on php's standard output (the html page being served back). 如果我运行没有选项的
curl_exec
,则获取的页面将在php的标准输出(正在提供的html页面)上输出。
If I run it with the RETURNTRANSFER
option set, I can get the whole page in a variable. 如果我使用
RETURNTRANSFER
选项设置运行它,我可以将整个页面放在一个变量中。
How can I get a stream, that I can then manually parse? 我怎样才能获得一个流,然后我可以手动解析?
In case 1, I cannot access the data to parse it and in case 2, I need to wait until it is fully downloaded before starting to parse it. 在案例1中,我无法访问数据来解析它,在案例2中,我需要等到它完全下载后再开始解析它。 I would like something similar to
fopen()
and fread()
where fread($curl_handle, 1000)
would return as soon as the first 1000 bytes have been read, and the second call would be return after 2000 bytes have been read, etc. 我想类似于
fopen()
和fread()
,其中fread($curl_handle, 1000)
将在读取前1000个字节后立即返回,第二个调用将在读取2000个字节后返回,等等。
You might be interested by this answer I gave some time ago : I explained and gave an example of using stream wrappers with curl, to be able to work with the data while it's being fetched -- which seems to be what you want to do. 您可能会对我前一段时间给出的答案感兴趣:我解释并给出了一个使用curl流包装器的示例,以便能够在获取数据时使用数据 - 这似乎就是您想要做的。
It's probably not an exact answer to your question, but it could be what you needed to start implementing a solution ;-) 这可能不是您问题的准确答案,但它可能是您开始实施解决方案所需要的;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.