fsockopen & SSL & SSL related errors...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

fsockopen & SSL & SSL related errors...

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why is this in General Discussion? :roll:


Moved to PHP - Code.
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post by tomfra »

Oopps... sorry Feyd, my fault.

Tomas
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post 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
Post Reply