Forum Moderators: coopster

Message Too Old, No Replies

Difference Between fopen(), fsockopen()

         

dougmcc1

7:50 pm on May 25, 2006 (gmt 0)

10+ Year Member



What's the difference between fopen() and fsockopen()?

coopster

9:14 pm on May 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



In one word? sockets [php.net]. fopen works with files, fsockopen works with resources through a socket.

dougmcc1

9:35 pm on May 25, 2006 (gmt 0)

10+ Year Member



So after following the link you provided I'm still wondering what a socket really is. Is it a connection to something?

Maybe it differs by what is trying to be accomplished with different scripts but in my case I'm guessing that fopen is used when accessing files on your site in local folders and directories (./folder/template.txt), whereas fsockopen would be used when accessing files outside of your site (http://www.notmysite.com/folder/template.txt).

Is this on target?

coopster

9:43 pm on May 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yep, right on target. fsockopen is indeed a connection. It returns a resource handle or file pointer.