[thelist] which is better: cURL vs. fsockopen [PHP]

Jay Blanchard jay.blanchard at niicommunications.com
Fri Jul 19 06:22:01 CDT 2002


[snip]
One is fsockopen() which works wonderfully... the only problem is
that I'm not familiar with "sockets" and I don't know if I'm doing
something that will adversely affect the new server or the remote
servers that I'm trying to connect to. I'm assuming that fsockopen()
is really fopen() with more options but... not my server and I don't
want to cause headaches :-)

The second is cURL. It looks straightforward in the documentation on
the PHP.net site. Unfortunately it doesn't appear that the new server
is configured with this though I guess I could ask for it.
[/snip]

It depends. Where cURL really shines is its ability to allow you to pass
authentication information to the remote server, allowing you to log in
'automagically', handy for use in a script. I use cURL in one instance where
the password must be changed frequently, so have the script login, change
the password (via an algorithm that creates a new password), and then
perform file retrieval functions. To retrieve a file from a remote host
requires less coding.

fsockopen() opens a file pointer, with which you can then use additional
functions for file retrieval. more coding than cURL. It shouldn't hurt
anything, but if you need to pass authentication info it will require
additional coding.

Once you have analyzed your situation you should be able to pick the best
method. If you cannot compile and use libcurl with PHP find out if it is
available on your server and use it from the command line. If this is the
case and you need to include it as part of a PHP script you can exec() it.

HTH!

Jay

"Two wrongs are only the beginning"

*************************************
* Want to meet other PHP developers *
* in your area? Check out:          *
* http://php.meetup.com/            *
* No developer is an island ...     *
*************************************





More information about the thelist mailing list