Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


fopen vs fsockopen

Posted on 2003-03-13
Medium Priority
Last Modified: 2013-12-12
I am performing a GET request from my server. I want to know whether fsockopen or fopen is better. Please give reasons in terms of speed and other aspects.

Thank you very much.
Question by:hostsol
  • 2

Accepted Solution

spookje earned 60 total points
ID: 8130403
If you just want to get a request from a web server,
I think fopen is easier programming style.

$thefile=fgets($fp,100000); /* 100000 is MAX, if you
                               don't know the MAX, you must  loop*/

Using a socket, you will have to send the HTTP request
by hand. It is certainly more attractive, but i think
it's like shooting a fly with a canon. :-)

Typically you will use a socket for communication with
rather unknown daemons/services (i.e. self-made).

In terms of speed, I do not know, but my guess is it must
be pretty much the same, either way.

Expert Comment

ID: 8130421
Just a little remark, using fopen, you can append the GET
variables to the end of the url - same as when you send
the GET request by hand using a socket.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question