Hi,
I have been reading up on fsockopen, fopen file() and file_get_contents() and am not sure if I understand it properly.
When we use these commands to download a web page, I assume that in reality PHP is ultimately using the same procedures (code) to connect to the remote server get the page. The different commands allow us access to different aspects of the procedure, correct ?
So this means that when we use the fopen() to open a file stream on a web page, PHP looks after the sockets for us. So PHP opens a socket on a default port by itself. After all a connection via a socket will be needed. So which port does PHP use for this - is it 80 ?
Then when we use file_get_contents(), again PHP must need to use both a socket and a handle, so presumably it uses fopensock() code (as above), then it also uses the fopen() code and creates a default handle where the second parameter is set to "rb" and it uses the fread() code to grab the contents by setting the bytes parameter to the filesize.
So the file_get_contents() is a nice short cut because PHP is handling the necessary steps for us, but behind the scenes the same code is being used to set up a connection on a port, create a file stream and read the file.
Is that about right ?
Would appreciate it if anyone who knows about how this works would correct me or fill me in on the bits I am missing
Thanks