I am getting this error message:

Warning: fsockopen() [function.fsockopen]: php_hostconnect: connect failed in /home/solspace/public_html/weather/weather.php on line 47

Warning: fsockopen() [function.fsockopen]: unable to connect to [url]www.msnbc.com:80[/url] in /home/solspace/public_html/weather/weather.php on line 47

The lines in question is this:

$fa = fsockopen("www.msnbc.com", 80, &$num_error, &$str_error, 30);
if(!$fa)
{ print "Weather is not available: $str_error ($num_error)\n"; }
else
{

fputs($fa,"GET /m/chnk/d/weather_d_src.asp?acid=$accid HTTP/1.0\n\n");

Where accid = USMI0704 to display my current METAR data.

THe same code works on the original page that has the script for download, and I can browse to the url in my browser to get the data.
I emailed my webhost and they say everything is okay on their end and its a problem with my script.

This is the complete URL:

http://www.msnbc.com/m/chnk/d/weath...p?acid=USMI0704

And as of 6:55pm est returns the following:

function makeWeatherObj() { this.swCity = "Redford"; this.swSubDiv = "MI"; this.swCountry = "USA"; this.swRegion = "United States"; this.swTemp = "23"; this.swTempCel = Math.round((5/9)*(this.swTemp-32)); this.swCIcon = "34"; this.swWindS = "15"; this.swWindD = "WSW"; this.swBaro = "30.19"; this.swHumid = "50"; this.swReal = "10"; this.swUV = "0"; this.swVis = "999.00"; this.swLastUp = "03/10/2003 17:54:00"; this.swConText = "Fair"; this.swFore = "3|4|5|6|7|03/11/2003|03/12/2003|03/13/2003|03/14/2003|03/15/ 2003|24|30|5|30|28|37|4|65|4|3|38|37|41|41|49|20|10|50|10|10|29|29|27|29|29|4|4|3|4|4|27|26|23|32|39
|"; this.swAcid = "USMI0704"; }

And this is the site that I got the script from:
http://balidwipa.com/weather

Any ideas at all? It used to work for me, but recently is just displays the error listed above.

Thanks in advance.

    Well, it should be easy enough to test whether your host company is telling the truth; the concept would just be to try an fsockopen on some other server.

    FWIW, I pasted your code onto one of my boxen and $fa came out true.....

      8 months later

      am trying to retrieve a web page that contains one paramater for example

      http://whatever.com:8084/?param1=value1

      The above URL works fine when I just cut and paste it into the web browser.

      However when I try to request it using my PHP code/fsockopen I keep getting the unable to connect error.

      I try my code on other website and it works so its not my hosting company issue?

      I just can't figure out why?

        Write a Reply...