sklar.com

...composed of an indefinite, perhaps infinite number of hexagonal galleries...

© 1994-2017. David Sklar. All rights reserved.

Parsing Reasonably-sized HTTP Responses

From with a PHP program, I’d like to make an HTTP request and use the response body in my program. What could be simpler? PHP has a zillion ways to do it, not limited to: file_get_contents(), fopen() and fread(), fsockopen(), curl, and PEAR HTTP_Request.



One additional requirement that makes this slightly more interesting: I don’t want to waste any memory on a response body that’s too big. If I slurp in a giant request body, I might run over my memory_limit.



Here’s what I came up with to solve this problem:


Continue reading “Parsing Reasonably-sized HTTP Responses”

Tagged with php