Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

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.

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.

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";

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top