In PHP, what are the biggest considerations when choosing between using http_get(“https://…”) and a sockets loop with fsockopen(“ssl://…”), fputs() and fread()?
I’ve seen a couple of implementations lately that use the latter. Is that just old legacy code or is there some good reason for it?
Thanks.
http_getrequires a PECL extension, which is not bundled with PHP.fsockopenis more complicated to use (requires looping, sending the headers manually, reading the headers manually, and, in general, more code), but is part of the PHP (it’s always present).In my opinion, the best fail-safe option is to use the http wrapper, as in:
The http wrapper, however, has its own set of limitations – no digest authentication, no automatic handling of encoded content, etc. So if either the PECL http extension or the curl extension are available, those would probably be a better option.