tags:

views:

264

answers:

1

Hello,

1/ If I run curl_exec with no options, the fetched page gets output on php's standard output (the html page being served back).

2/ 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.

Thanks!

+1  A: 

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 ;-)

Pascal MARTIN
Wow thanks, that looks great, I'm just a little disappointed that there is no built-in way of doing it, but I'll try with your class.
Laurent
Tou're welcome :-) ;; well, I suppose what you are trying to do is not that common ^^ ;; but it's kind of "built-in", afterall : streams are a great functionnality of PHP, even if not used quite enough...
Pascal MARTIN