I'm not sure either is best. The two functions do different things.
fopen() is designed to open a file handle. It can talk to HTTP, FTP, or your filesystem and return a file handle to read or write (except for HTTP) to the file.
fsockopen() just opens a TCP/IP socket connection from your machine to another one (or in the case of UDP, just sends a packet to the other one). What you do with it from there is your business. fsockopen() gives you very fine control over the socket, especially if you're running PHP on a Unix-like OS.
If you know all the commands which go back and forth from your various client apps and their respective servers (HTTP, FTP, Gopher, SMTP, POP3, etc), the sky is the limit in what fsockopen() can do for you. If you just need to suck down a web-page, fopen() will probably do what you need. There are also other specialized PHP families of functions for other high-level protocols -- FTP for example.
Something that comes to mind as a first use a lot of people will have for fsockopen() is to be able to send POST-method form data to a web script. This requires you to write to the handle the HTTP headers, then the form data. After that you can retrieve the page as generated by the web server by reading from the handle. You can't do what with fopen() because a handle it opens to an HTTP resource is read-only. ______________________________________________________________________
TANSTAAFL!
thanx, what i do is just reading a daily changed info from the other server and including that into my html code - no ftp, submiting form info or other stuff you mentioned
sometimes the other server responses that it's busy (as i remember it's one of the 5xx http errors) - isn't the error code returned quicker while using the sockets? when using fopen() the page pauses loading while waiting for the other server's response
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.