1

I have a php based website which is connecting to a third party SOAP web service.

I am creating and parsing the request and response envelope xml successfully. The only issue is with the actual communication. I am using sockets, as I saw this code as an example and was able to modify it to work for our case.

$socket = fsockopen("ssl://***",443);
if ($socket!==false){
  $request =  "POST /***.asmx HTTP/1.1\n".
              "Host: ***\n".
              "Content-Type: text/xml; charset=utf-8\n".
              "Content-Length: ".strlen($request)."\n".
              "SOAPAction: \"http://***\"\n\n".
              $request."\n";

  fputs($socket, $request); 

However reading the response was always hanging until the connection timed out. This is due to the method I use to read FGETS requiring an end of line or end of file marker, which it doesn't receive from the web service. As a result I am forced to read the response one byte at a time and check if the SOAP envelope is closed, and then manually stop. This seems somewhat inefficient to me.

  while (!feof($socket) && substr($response,-16) != "</soap:Envelope>" ) {
     $response .= fgets($socket,2);  // force read one byte at a time
  }

So, my question(s) are: Is this a known phenomenon for .net web services? Is there a better way to perform this communication, or specifically the read (other than FGETS)?

And on a slightly unrelated note, why does the fgets function require me to specify 2, to read 1 byte? (Or is this related to the charset, ie: if the response is in utf8 then 1 character is represented by 2 bytes)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.