Re: Re: fsockopen on ssl://

From: Date: Sun, 18 May 2008 22:26:58 +0000
Subject: Re: Re: fsockopen on ssl://
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-274496@lists.php.net to get a copy of this message
Are you doing the command line on the same machine as the server? Have you checked out the apache configuration? Since phpcli runs alone. (iirc) 2008/5/18 bob pilly <bobpilly@yahoo.co.uk>: > Hi Manuel > > Thanks for the reply. I have tested it with a timeout of 20 seconds and the same thing occurs. > It works as before from the command line and not form within apache.. Any more ideas? > > Cheers > > Bob > > > ----- Original Message ---- > From: Manuel Lemos <mlemos@acm.org> > To: bob pilly <bobpilly@yahoo.co.uk> > Cc: php-general@lists.php.net > Sent: Wednesday, 14 May, 2008 4:26:41 PM > Subject: 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/ > > > > __________________________________________________________ > Sent from Yahoo! Mail. > A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html

« previous php.general (#274496) next »