Hello All:
Wow, its great to have this board back! Anyway, heres a wierd issue:
I recently decided to move my site to my our domain. The php scripts im trying to move are currently are woking perfectly on their current site. Here is an example:
http://www.anchorageweather.i4host.net/station/anchorageforecast.phpHowever, when I tried to migrate th files to the new server hosting my new domain name - the scripts would not work totally. Thats to say they will display; however, the "Advanced NOAA 7-Day forecast" script will not update forecast.txt ?!?
Hmm...strange, its the exact same file and it works on the previous server.
Here is a link to a file I made that will help everyone "see the problem". Click here:
http://eetee.us/station/checkforcasttime.htmOn this page you should be able to see the contents of forecast.txt with a clock showing current universal time. The page also has two links that, when clicked should force the cashe to update. However, if you refresh the page with the clock you can see the time on forecast.txt did not update - the file did not "resave".
The same php script on the previous server works great ?!?
Here is the code for advanchorageforecast.php:
<?php
/*------------------------------------------------
//
//This is a more advanced version of the forecast script
//It uses file caching and feed failure to better handle when NOAA is down
//
//import NOAA Forecast info
//data ends up in three different arrays:
//$forecasticons[x] x = 0 thru 9 This is the icon and text around it
//$forecasttitles[x] x = 0 thru 12 This is the title word for the time period
//$forecasttext[x] x = 0 thru 12 This is the detail text for the forecast
//
//And one more variable - $lastupdate This is the time of last update
//
//Also, in order for this to work correctly, you need the NOAA icons (or make your own...
//there are over 200!). These need to be placed in the path where the original NOAA icons
//are located. In my case, they are at: \forecast\images\
//properly (so make a folder in your web HTML root called "forecast", then make a folder in it
//called "images", and place the icons in this folder)
//
//http://members.cox.net/carterlakeweather/forecasticons.zip (380K)
//
//URL below --MUST BE-- the Printable Point Forecast from the NOAA website
//
//Not every area of the US has a printable point forecast
//
//This script will ONLY WORK with a printable point forecast!
//
//To find yours in your area:
//
//Go to www.noaa.gov
//Click on the Storm Watch map (middle lower left of page)
//Click on your state
//Click on your area of the state
//Scroll down to the "Additional Forecasts & Info"
//Click on Printable Forecast
//------------------------------------------------*/
// Get the forecast.txt file or a new one from NOAA
// You have to have a forecast.txt in place for this script to work
// You can see ours at http://www.carterlake.org/forecast.txt
// This is version 1.1 with Ken's modifications from Saratoga Weather
// http://saratoga-weather.org/
// You can now force the cache to update by adding ?force=1 to the end of the URL
if ( empty($_REQUEST['force']) )
$_REQUEST['force']="0";
$Force = $_REQUEST['force'];
$cacheName = "forecast.txt";
$fileName = "http://www.crh.noaa.gov/forecast/MapClick.php?FcstType=text&textField1=38.275297&textField2=-85.526168&site=lmk&TextType=2";
// The number 1800 below is the number of seconds the cache will be used instead of pulling a new file
// 1800 = 60s x 30m so it retreives every 30 minutes.
if ($Force==1) {
$html = fetchUrlWithoutHanging($fileName,$cacheName);
$fp = fopen($cacheName, "w");
$write = fputs($fp, $html);
fclose($fp); }
if (filemtime($cacheName) + 1800 > time()) {
$html = implode('', file($cacheName));
} else {
$html = fetchUrlWithoutHanging($fileName,$cacheName);
$fp = fopen($cacheName, "w");
$write = fputs($fp, $html);
fclose($fp); }
// Just get the top of the NWS page for editing
preg_match('|<tr valign ="top" align="center">(.*)<table width="670"|s', $html, $betweenspan);
$forecastop = $betweenspan[1];
// Chop up each icon html and place in array
preg_match_all("/<td.*>(.*)<\/td>/Uis", $forecastop, $headers);
$forecasticons = $headers[1];
// Now get just the bottom of the NWS page for editing
preg_match('|</table>(.*)<hr>|s', $html, $betweenspan);
$forecast = $betweenspan[1];
// Chop up each title text and place in array
preg_match_all('|<b>(.*): </b>|Ui', $forecast, $headers);
$forecasttitles = $headers[1];
// Chop up each forecast text and place in array
preg_match_all('|</b>(.*)<br>|Ui', $forecast, $headers);
$forecasttext = $headers[1];
// Grab the Last Update date and time.
preg_match('|Last Update: (.*)|', $html, $betweenspan);
$lastupdate = $betweenspan[1];
function fetchUrlWithoutHanging($url,$cacheurl)
{
// Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
$numberOfSeconds=4;
// Suppress error reporting so Web site visitors are unaware if the feed fails
error_reporting(0);
// Extract resource path and domain from URL ready for fsockopen
$url = str_replace("http://","",$url);
$urlComponents = explode("/",$url);
$domain = $urlComponents[0];
$resourcePath = str_replace($domain,"",$url);
// Establish a connection
$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);
if (!$socketConnection)
{
$html = implode('', file($cacheurl));
return($html);
// You may wish to remove the following debugging line on a live Web site
// print("<!-- Network error: $errstr ($errno) -->");
} // end if
else {
$xml = '';
fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
// Loop until end of file
while (!feof($socketConnection))
{
$xml .= fgets($socketConnection, 4096);
} // end while
fclose ($socketConnection);
} // end else
return($xml);
} // end function
?>
<html>
<head>
</head>
<body bgcolor=#FFFFBB>
<?php
// if the forecast text is blank, prompt the visitor to force an update
if (strlen($forecasttext[0])<2) {
echo '<br/><br/>Forecast blank? <a href="' . $PHP_SELF . '?force=1">Force Update</a><br/><br/>';
} ?>
<table width="670" border="0" align="center" cellpadding="0" cellspacing="0">
<tr valign ="top" align="center">
<td>
<center><font face="verdana,arial" size="4"><b>Anchorage KY Forecast</b></font></center><center><font face="verdana,arial" size="1">Last updated <?echo $lastupdate?></font></center>
</td>
<td>
<a href=javascript:window.print()><img src="/forecast/images/12.gif" border=0 height=35 width=30 alt=Print title=Print></a>
</td>
</tr>
</table>
<br><br>
<table width="670" border="0" align="center" cellpadding="0" cellspacing="0">
<tr valign ="top" align="center">
<td width="11%">
<font face="verdana,arial" size="1">
<?echo $forecasticons[0]?>
</td>
<td width="11%">
<font face="verdana,arial" size="1">
<?echo $forecasticons[1]?>
</td>
<td width="11%">
<font face="verdana,arial" size="1">
<?echo $forecasticons[2]?>
</td>
<td width="11%">
<font face="verdana,arial" size="1">
<?echo $forecasticons[3]?>
</td>
<td width="11%">
<font face="verdana,arial" size="1">
<?echo $forecasticons[4]?>
</td>
<td width="11%">
<font face="verdana,arial" size="1">
<?echo $forecasticons[5]?>
</td>
<td width="11%">
<font face="verdana,arial" size="1">
<?echo $forecasticons[6]?>
</td>
<td width="11%">
<font face="verdana,arial" size="1">
<?echo $forecasticons[7]?>
</td>
<td width="11%">
<font face="verdana,arial" size="1">
<?echo $forecasticons[8]?>
</td>
</tr>
</table>
<br><br><br>
<table width="670" border="0" align="center" cellpadding="0" cellspacing="0">
<tr valign ="top">
<td valign="top" align="left"><font face="verdana,arial" size="2">
<b><?echo $forecasttitles[0]?>: </b><?echo $forecasttext[0]?><br>
<br>
<b><?echo $forecasttitles[1]?>: </b><?echo $forecasttext[1]?><br>
<br>
<b><?echo $forecasttitles[2]?>: </b><?echo $forecasttext[2]?><br>
<br>
<b><?echo $forecasttitles[3]?>: </b><?echo $forecasttext[3]?><br>
<br>
<b><?echo $forecasttitles[4]?>: </b><?echo $forecasttext[4]?><br>
<br>
<b><?echo $forecasttitles[5]?>: </b><?echo $forecasttext[5]?><br>
<br>
<b><?echo $forecasttitles[6]?>: </b><?echo $forecasttext[6]?><br>
<br>
<b><?echo $forecasttitles[7]?>: </b><?echo $forecasttext[7]?><br>
<br>
<b><?echo $forecasttitles[8]?>: </b><?echo $forecasttext[8]?><br>
<br>
<b><?echo $forecasttitles[9]?>: </b><?echo $forecasttext[9]?><br>
<br>
<b><?echo $forecasttitles[10]?>: </b><?echo $forecasttext[10]?><br>
<br>
<b><?echo $forecasttitles[11]?>: </b><?echo $forecasttext[11]?><br>
<br>
<b><?echo $forecasttitles[12]?>: </b><?echo $forecasttext[12]?>
</td>
</tr>
</table>
</body>
</html>
Does anyone see anything glaring that I might be doing wrong when transfering the files from one host to another?!? Any help would be great. I hope I didn't pay alot of money for my new domain name and hosting service that won't work for me