Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multiple requests with a single socket using fsockopen and ssl.

Posted on 2008-06-23
3
Medium Priority
?
1,496 Views
Last Modified: 2013-12-25
I am writing a time sensitive script to submit socket-based (XML) requests at a certain time, in competition with other people running similar scripts.  There are time limits on how often I can send requests and a limit that I can only have one connection open at a time.  This leads me to belive that it's possible to have more than one request per connection. Is this correct? if so, how do I implement it?

Or, is it the case that a socket always get closed when a response is sent?

My best guess at implementation is below, but feels far from right.

Thanks!

$fp = fsockopen(example.com, 443);
 
$out = "GET /page1.html HTTP/1.1\r\n";
$out .= "Host: https://example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
  while (!feof($fp)) {
  echo fgets($fp, 128);
}
 
 
$out = "GET /page2.html HTTP/1.1\r\n";
$out .= "Host: https://example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
  while (!feof($fp)) {
  echo fgets($fp, 128);
}
 
fclose($fp);

Open in new window

0
Comment
Question by:mohrc
[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
3 Comments
 
LVL 20

Expert Comment

by:virmaior
ID: 21855792
I don't believe what you are doing will work..

it would depend on how their socket is coded.

At the very least, you will need to send an EOF (or equivalent device) to tell it when to end a statement.  

As written, you are not signaling the server that a new request is being made so the subsequent requests will not work.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 1000 total points
ID: 21868300
> $fp = fsockopen(example.com, 443);
are you "speaking" plain text on a SSL port? Just wondering?

Back to you question:
> .. it's possible to have more than one request per connection.
yes, use:

$out .= "Connection: keep-alive\r\n\r\n";


but depends on the server if it allows it.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

604 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