HTTP-Requests with php - An overview of extensions and classes
Datum: 07.01.2010 01:54:30PHP offers a lot of ways for requesting (GET) content via http(s) (and other protocols) and sending POST-Requests, if you need it for accessing an API, downloading files, unittests for a webservice, login-requests or whatever.
The extensions behind all those variantes are sockets (fsockopen()), streams (stream_socket_client()), curl or the PECL Extension Pecl_Http. Not all are usable on every host because of the php-configuration and the compiled/loaded extensions.
Here is a list of extensions and php-classes which can help you with those topics.
PHP Http(s) Request Classes
| Class | Backend-Extension | Features |
Version / PHP Version / license |
Snippets / Tutorials |
|---|---|---|---|---|
| PEAR Http_Request | streams, sockets |
Authentication (basic) Compression (gzip/deflate) Cookies Encryption (ssl) File Uploads Proxies (Authentication) |
1.4.4 (2008-11-17) (superseeded by HTTP_Request2) PHP 4.2.0 BSD License |
|
| PEAR Http_Request2 | streams, ext/curl |
Authentication (basic, digest) Compression (gzip/deflate) Cookies Encryption (ssl) File Uploads Proxies (Authentication) SSL Certificates |
0.5.1 (alpha) (2009-11-21) PHP 5.1.4 BSD License |
|
| PEAR Net_Curl | ext/curl |
Authentication (basic) Encryption (ssl) Cookies File Uploads Proxies (Authentication) SSL Certificates Curl-Access |
1.2.5 (2008-05-03) (superseeded by HTTP_Request2) PHP 4.2.0 New BSD License |
|
| PECL Pecl_Http |
ext/Pecl_Http (needs ext/curl) |
Authentication (basic, digest, GSS-Negotiate, NTLM) Compression (gzip/deflate) Cookies Encryption (ssl) Filesize and Speed-limits (min/max) for Requests File Uploads Multiple synchron Requests (HttpRequestPool) Proxies (Authentication) SSL Certificates |
1.6.6 (2009-12-10) PHP 4.3 New BSD License |
|
| Zend_Http_Client | streams, ext/curl |
Authentication (basic) Encryption (ssl) Cookies Curl-Access File Uploads Proxies (Authentication) Extendable with additional Adapters |
1.9.6 (2009-11-23) PHP 5.2.4 New BSD License |
Snippet for File-Upload with Zend_Http_Client |
| Wordpress WP_Http / WP_Http_Curl | sockets, ext/curl |
Encryption (ssl) Compression (gzip/deflate) Cookies Proxies (Authentication) |
2.8.6 (2009-11-12) PHP 4.3 GPL v2 |
|
| Curl | ext/curl |
Authentication (basic, digest, GSS-Negotiate, NTLM) Big File Downloads Cookies Encryption (ssl) File Uploads FTP(S) Upload/List Many other protocols (HTTP, HTTPS, LDAP, LDAPS, FTP, FTPS, TFTP, SCP, SFTP) Multiple synchron requests (curl_multi) Proxies (Authentication) SSL Certificates |
libcurl-version: 7.19.7 (2009-11-04) PHP 4 (some Options need 5.0, 5.1 or 5.2.10) extension: PHP-License libcurl: MIT/X |
Snippet for File-Upload with curl |
| Snoopy | sockets, curl-binary |
Authentication (basic) Cookies Encryption (ssl) File Uploads Proxies (Authentication) |
1.2.4 (2008-10-22) |
Snippet for File-Upload with Snoopy |
| CakePHP HttpSocket | sockets |
Encryption (ssl) Cookies |
1.2.5 (2009-09-08) PHP 4.3.2 MIT License |
Some people will notice that not all Classes which use Curl are capable of all Features curl offers, that's because I only mentioned features the classes/functions offer itself (even
when using only sockets) and in some classes you can't even access the curl-resource, WP_Http_Curl for example creates the resource insides as a local variable which you can't
manipulate, so you can't use setopt to set all the Options possibly needed by curl, Snoopy doesn't use ext/curl, it uses the curl-binary if available for some things. I added the
feature "Curl-Access" if the classes allow to inject the curl-instance or allows to directly manipulate the curl-instance-options, which doesn't mean you can use every feature of curl
with this class, but at least can change some more settings and parameters.
Some of the curl-extensions abilitys (protocols like scp, sftp) are only available if the newest version of libcurl is used and if libcurl was compiled with the right flags and the
right libs where intalled (like libssh2 for scp-support) and controlling some Features depends on the php-version. For more information on curl look in the php-manual.
I used Snoopy for a long long time, it is simple and worked for most requests, since I began using the Zend Framework I switched to Zend_Http_Client, only on rare occasion if I need
special features like the multiple synchron requests or downloading files bigger than memory_limit, i use a simple curl/curl_multi wrapper.
Did I forget something ? Any misspelling ? Do you know another Class for HTTP-Requests ? Or some Tutorials / Snippets for one of the listed ?
Write a comment !
Trackbacks (0)
Trackbackurl: http://www.robo47.net/trackback/blogentry/191Es sind keine Trackbacks vorhanden.
You liked it ? Link it on your homepage or blog:



Benjamin Steininger ist Webentwickler auf der Suche nach einem neuen Job und
photographiert sehr gerne. Er beschäftigt sich viel mit dem Internet, PHP, Symfony, Testing und hat einen
Kommentare (0)
Es sind noch keine Kommentare vorhanden.
Die Kommentare zu diesem Beitrag sind gesperrt.