Page 1 of 1

fsockopen & SSL & SSL related errors...

Posted: Wed Jan 19, 2005 9:18 am
by tomfra
I am using the below code to connect to one website through fsockopen, which requires SSL connection:

Code: Select all

$fp = fsockopen('ssl://domain.com', 443, $errno, $errstr, 30); 

if (!$fp) { echo "$errstr ($errno)<br>\n"; } else {

  $out = "POST /dir/ HTTP/1.1\r\n"; 
  $out .= "Host: domain.com\r\n"; 
  $out .= "Content-type: application/x-www-form-urlencoded\r\n"; 
  $out .= "Content-length: ".strlen($poststring)."\r\n"; 
  $out .= "Connection: close\r\n\r\n"; 
  $out .= "$poststring \r\n\r\n";
  
  fwrite($fp, $out);

  { while (!feof($fp)) { echo fread($fp, 4096); }}
  fclose($fp); 
}
The $poststring variable is created before this code.

It usually works just fine but sometimes it can't connect properly and I find this error message in error.log:

PHP Warning: fread(): SSL: fatal protocol error in ...

I can't find the reason for it because it doesn't happen always. Any idea what it could be caused by?

Thanks!

Tomas

Posted: Wed Jan 19, 2005 9:27 am
by timvw
i've never seen a wrapper that has ssl..

what i've seen is a wrapper for https......

http://be.php.net/manual/en/wrappers.php

Posted: Wed Jan 19, 2005 9:34 am
by tomfra
From php.net (http://cz.php.net/manual/en/function.fsockopen.php):
As of PHP 4.3.0, if you have compiled in OpenSSL support, you may prefix the hostname with either 'ssl://' or 'tls://' to use an SSL or TLS client connection over TCP/IP to connect to the remote host.
It does indeed work, but it seems to be somewhat...buggy.

Tomas

Posted: Wed Jan 19, 2005 9:46 am
by feyd
why is this in General Discussion? :roll:


Moved to PHP - Code.

Posted: Wed Jan 19, 2005 9:51 am
by tomfra
Oopps... sorry Feyd, my fault.

Tomas

Posted: Wed Jan 19, 2005 7:21 pm
by tomfra
OK, I am sure somebody has an idea what the problem could be? Don't be shy and let me know... please :P

Tomas