36

I'm using this to check for the availability of a URL:

$fp = fsockopen($url, 443, $errno, $errstr);

and I get this error back...

Warning: fsockopen() [function.fsockopen]: unable to connect to https://example.com/soapserver.php:443 (Unable to find the socket transport "https" - did you forget to enable it when you configured PHP?) in C:\Home etc etc....

I'm using an IIS server btw,( no its not my doing! ) so I think its something to do with not having open-ssl, but I'm not sure. Can anyone help please?

I did a phpinfo() and I do have ssl, but on IMAP and cURL, thats all.

Any ideas?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Chris J Allen
  • 18,970
  • 20
  • 76
  • 114

6 Answers6

47

Uncomment the line: extension=php_openssl.dll in php.ini

sth
  • 222,467
  • 53
  • 283
  • 367
Sérgio
  • 1,597
  • 2
  • 12
  • 16
  • Do I need to do anything with php (sorry being a newbie on php) after I edited that file? Thank you. – uudaddy Oct 07 '20 at 14:55
  • Just realized this line is for Windows (dll), and it does not apply to Linux which I am using. – uudaddy Oct 07 '20 at 15:23
29

You should be using just the hostname, not the URL in the fsockopen call. You'll need to provide the uri, minus the host/port in the actual HTTP headers. As @Martijin noted, and as listed in the manual page, you'll need to preface your host name with ssl:// for SSL or tls:// if using transport layer security.

Manual page for fsockopen. Look at Example #1.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
17

also for ssl you need to prefix the host with ssl://

Martijn Laarman
  • 13,476
  • 44
  • 63
4

Let's say you wanted to grab NY Times, which enforces HTTPS:

Incorrect:

$client = stream_socket_client('https://www.nytimes.com', $errno, $errstr, 30);

Correct:

$client = stream_socket_client('tcp://www.nytimes.com:443', $errno, $errstr, 30);

Note I've replaced https:// with tcp:// and appended the 443 port to the hostname.

I guess we can say that stream_socket_client() does not speak URLs.

The Onin
  • 5,068
  • 2
  • 38
  • 55
2

Switching to ssl:// worked for me but I kept getting a BAD REQUEST response. I found that I needed to add one more line to declare explicitly my Host Header as described here and ensure that I've updated my HTTP from HTTP/1.0 to HTTP/1.1:

$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";
Community
  • 1
  • 1
Tony Schmidt
  • 171
  • 2
  • 3
0

Check curl installed or not for php. if it is not installed install the curl. for windows Uncomment the line: extension=php_openssl.dll in php.ini, for ubuntu sudo apt-get install php-curl

S.Abbu
  • 11
  • 4