?
Solved

fopen vs fsockopen

Posted on 2003-03-13
2
Medium Priority
?
975 Views
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.
0
Comment
Question by:hostsol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
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.

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

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.
0
 
LVL 1

Expert Comment

by:spookje
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

770 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