Solved

Multiple requests with a single socket using fsockopen and ssl.

Posted on 2008-06-23
3
1,429 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 250 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

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

Suggested Solutions

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 is …
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 dynamically set the form action using jQuery.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

735 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