Bluehost.com Web Hosting $6.95

fsockopen on ssl://

This is a discussion on fsockopen on ssl:// within the PHP General forums, part of the PHP Programming Forums category; Hi all I have tried researching this issue but havent come up with anysolution so im hoping someone has seen ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-13-2008
bob pilly
 
Posts: n/a
Default fsockopen on ssl://

Hi all

I have tried researching this issue but havent come up with anysolution so im hoping someone has seen it before and can help. I have the following test script that uses fsockopen to connect to a https site, get the contents and outputs it.

<?php
$host = "www.microsoft.com";
$path = "/";
$fh = fsockopen("ssl://".$host, 443, $errno, $errstr, 5);//opens url for reading with a timeout of 2 seconds

if (!$fh){
echo "FAIL: $errno $errstr ";
}
else{
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n";
$out .= "\r\n";
fwrite($fh, $out);
stream_set_timeout($fh,2);
$info = stream_get_meta_data($fh);
if($info['timed_out']){
echo "TIMEOUT\n";
}
else{
$haystack = "";
while (!feof($fh)) {
$haystack.= fgets($fh, 4096);
}
}
print $haystack;
fclose($fh);
}
?>

if i run this script using php -f test.php it works fine. However if i try and run this on my loca apache server i get the following error:

Warning: fsockopen() [function.fsockopen]:unable to connect tossl://www.microsoft.com:443 (A connection attemptfailed because the connected party did not properly respond after aperiod of time, or established connection failed because connected hosthas failed to respond.) in C:\ProgramFiles\Apache Software Foundation\Apache2.2\htdocs\test.php on line 4
FAIL: 10060 A connection attempt failed because the connected party didnot properly respond after a period of time, or established connectionfailed because connected host has failed to respond.

As you can see from that error i am using windows and apache 2.2. My php version is 5.25. I have Registered Stream Socket Transports tcp, udp, ssl, sslv3, sslv2, tlsin my config.

Thanks for any help in advance and it is greatly appreciated, this problem is driving me nuts!!

Cheers

Bob




__________________________________________________ ________
Sent from Yahoo! Mail..
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html
Reply With Quote
  #2 (permalink)  
Old 05-14-2008
Manuel Lemos
 
Posts: n/a
Default Re: fsockopen on ssl://

Hello,

on 05/13/2008 04:37 PM bob pilly said the following:
> Hi all
>
> I have tried researching this issue but havent come up with any solution so im hoping someone has seen it before and can help. I have the following test script that uses fsockopen to connect to a https site, get the contents and outputs it.
>
> <?php
> $host = "www.microsoft.com";
> $path = "/";
> $fh = fsockopen("ssl://".$host, 443, $errno, $errstr, 5);//opens url for reading with a timeout of 2 seconds
>
> if (!$fh){
> echo "FAIL: $errno $errstr ";
> }
> else{
> $out = "GET $path HTTP/1.1\r\n";
> $out .= "Host: $host\r\n";
> $out .= "Connection: Close\r\n";
> $out .= "\r\n";
> fwrite($fh, $out);
> stream_set_timeout($fh,2);
> $info = stream_get_meta_data($fh);
> if($info['timed_out']){
> echo "TIMEOUT\n";
> }
> else{
> $haystack = "";
> while (!feof($fh)) {
> $haystack.= fgets($fh, 4096);
> }
> }
> print $haystack;
> fclose($fh);
> }
> ?>
>
> if i run this script using php -f test.php it works fine. However if i try and run this on my loca apache server i get the following error:
>
> Warning: fsockopen() [function.fsockopen]:unable to connect to ssl://www.microsoft.com:443 (A connection attemptfailed because the connected party did not properly respond after aperiod of time, or established connection failed because connected hosthas failed to respond.) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test.php on line 4
> FAIL: 10060 A connection attempt failed because the connected party didnot properly respond after a period of time, or established connectionfailed because connected host has failed to respond.
>
> As you can see from that error i am using windows and apache 2.2. My php version is 5.25. I have Registered Stream Socket Transports tcp, udp, ssl, sslv3, sslv2, tlsin my config.


I suspect that you are giving a very short timeout but then you are not
handling the timeout error properly.

Anyway, before reinventing the wheel, you may to try this HTTP client
class that supports many options including establishing SSL corrections
and setting and handling timeouts correctly.

http://www.phpclasses.org/httpclient

--

Regards,
Manuel Lemos

PHP professionals looking for PHP jobs
http://www.phpclasses.org/professionals/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:24 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0