Getting the cURL stream in PHP

curl, php, stream

Solution

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.

It's probably not an exact answer to your question, but it could be what you needed to start implementing a solution ;-)

Problem

If I run `curl_exec` with no options, the fetched page gets output on php's standard output (the html page being served back). If I run it with the `RETURNTRANSFER` option set, I can get the whole page in a variable. 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. 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.

Original source

Related problems