sp-niemand
sp-niemand

Reputation: 225

How to get an HTTP response as a stream in PHP?

My application's backend in PHP sends HTTP requests to other servers and receives large responses from them.

At the moment I'm using curl_setopt($curlResource, CURLOPT_FILE, $fileResource); to avoid storing the response in memory so I don't have to increase memory limits for the script.

What I want to achieve is for my script to receive the HTTP response from other server and to process it in real-time, discarding pieces of data already processed.

Is it even possible without something fancy like a socket connection to ports 80 or 443 to receive data without the help of CURL?

Upvotes: 0

Views: 11007

Answers (1)

sp-niemand
sp-niemand

Reputation: 225

Brief answer: use your own custom stream object as a CURLOPT_FILE.

You can find more info here: https://stackoverflow.com/a/1342760/227884 .

Upvotes: 1

Related Questions