Author Topic: New php host not working right?!?  (Read 6559 times)

0 Members and 1 Guest are viewing this topic.

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
New php host not working right?!?
« on: August 13, 2006, 09:04:16 PM »
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.php

However, 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.htm
On 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:

Code: [Select]

<?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&#58; 
//$forecasticons[x&#93;  x = 0 thru 9   This is the icon and text around it 
//$forecasttitles[x&#93;  x = 0 thru 12   This is the title word for the time period 
//$forecasttext[x&#93;  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 &#40;or make your own... 
//there are over 200!&#41;. These need to be placed in the path where the original NOAA icons
//are located. In my case, they are at&#58; \forecast\images\
//properly &#40;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&#41;
//
//http&#58;//members.cox.net/carterlakeweather/forecasticons.zip &#40;380K&#41;
//
//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&#58; 
// 
//Go to www.noaa.gov 
//Click on the Storm Watch map &#40;middle lower left of page&#41; 
//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&#58;//www.carterlake.org/forecast.txt

// This is version 1.1 with Ken's modifications from Saratoga Weather
// http&#58;//saratoga-weather.org/

// You can now force the cache to update by adding ?force=1 to the end of the URL

if &#40; empty&#40;$_REQUEST['force'&#93;&#41; &#41; 
        
$_REQUEST['force'&#93;="0";

$Force $_REQUEST['force'&#93;;

$cacheName "forecast.txt"
$fileName "http&#58;//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 &#40;$Force==1&#41; &#123;
      
$html fetchUrlWithoutHanging&#40;$fileName,$cacheName&#41;; 
      
$fp fopen&#40;$cacheName, "w"&#41;; 
      
$write fputs&#40;$fp, $html&#41;; 
      
fclose&#40;$fp&#41;;  &#125; 

if &#40;filemtime&#40;$cacheName&#41; + 1800 > time&#40;&#41;&#41; &#123; 
      
$html implode&#40;'', file&#40;$cacheName&#41;&#41;; 
    
&#125; else &#123; 
      
$html fetchUrlWithoutHanging&#40;$fileName,$cacheName&#41;; 
      
$fp fopen&#40;$cacheName, "w"&#41;; 
      
$write fputs&#40;$fp, $html&#41;; 
      
fclose&#40;$fp&#41;;  &#125; 

      // Just get the top of the NWS page for editing 

      
preg_match&#40;'|<tr valign ="top" align="center">&#40;.*&#41;<table width="670"|s', $html, $betweenspan&#41;; 
      
$forecastop  $betweenspan[1&#93;; 

      // Chop up each icon html and place in array 
      
preg_match_all&#40;"/<td.*>&#40;.*&#41;<\/td>/Uis", $forecastop, $headers&#41;; 
      
$forecasticons $headers[1&#93;; 

      // Now get just the bottom of the NWS page for editing 
      
preg_match&#40;'|</table>&#40;.*&#41;<hr>|s', $html, $betweenspan&#41;; 
      
$forecast  $betweenspan[1&#93;; 

      // Chop up each title text and place in array 
      
preg_match_all&#40;'|<b>&#40;.*&#41;&#58; </b>|Ui', $forecast, $headers&#41;; 
      
$forecasttitles $headers[1&#93;; 

      // Chop up each forecast text and place in array 
      
preg_match_all&#40;'|</b>&#40;.*&#41;<br>|Ui', $forecast, $headers&#41;; 
      
$forecasttext $headers[1&#93;; 

      // Grab the Last Update date and time. 
      
preg_match&#40;'|Last Update&#58; &#40;.*&#41;|', $html, $betweenspan&#41;; 
      
$lastupdate  $betweenspan[1&#93;; 

function fetchUrlWithoutHanging&#40;$url,$cacheurl&#41;
   
&#123;
   // Set maximum number of seconds &#40;can have floating-point&#41; 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&#40;0&#41;;

   // Extract resource path and domain from URL ready for fsockopen

   
$url str_replace&#40;"http&#58;//","",$url&#41;;
   
$urlComponents explode&#40;"/",$url&#41;;
   
$domain $urlComponents[0&#93;;
   
$resourcePath str_replace&#40;$domain,"",$url&#41;;

   // Establish a connection
   
$socketConnection fsockopen&#40;$domain, 80, $errno, $errstr, $numberOfSeconds&#41;;

   
if &#40;!$socketConnection&#41;
       
&#123;

       
$html implode&#40;'', file&#40;$cacheurl&#41;&#41;;
       
return&#40;$html&#41;;

       // You may wish to remove the following debugging line on a live Web site
       // print&#40;"<!-- Network error&#58; $errstr &#40;$errno&#41; -->"&#41;;
       
&#125;    // end if
   
else    &#123;
       
$xml '';
       
fputs&#40;$socketConnection, "GET $resourcePath HTTP/1.0\r\nHost&#58; $domain\r\n\r\n"&#41;;
   
       // Loop until end of file
       
while &#40;!feof&#40;$socketConnection&#41;&#41;
           
&#123;
           
$xml .= fgets&#40;$socketConnection, 4096&#41;;
           
&#125;    // end while

       
fclose &#40;$socketConnection&#41;;

       
&#125;    // end else

   
return&#40;$xml&#41;;

   
&#125;    // end function


?>


<html>
<head>
</head>
<body bgcolor=#FFFFBB>


<?php

// if the forecast text is blank, prompt the visitor to force an update

if &#40;strlen&#40;$forecasttext[0&#93;&#41;<2&#41; &#123;

echo '<br/><br/>Forecast blank? <a href="' $PHP_SELF '?force=1">Force Update</a><br/><br/>';

&
#125; ?>


<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  :(
South of the Tracks, Anchorage, KY

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 8644
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
New php host not working right?!?
« Reply #1 on: August 13, 2006, 09:15:56 PM »
That's definitely the correct version of Tom's advforecast.php script.

I just checked your URL:
http://www.anchorageweather.i4host.net/station/anchorageforecast.php

And got a nicely formatted forecast.  It may have been that you didn't 'seed' the new host with a forecast.txt file so the PHP script could write it.  Some PHP / file system implementations allow PHP scripts to read/write but not create a file.

It looks like it's working fine now :-)

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
New php host not working right?!?
« Reply #2 on: August 13, 2006, 09:26:52 PM »
Quote from: "kenmtrue"
That's definitely the correct version of Tom's advforecast.php script.

I just checked your URL:
http://www.anchorageweather.i4host.net/station/anchorageforecast.php

And got a nicely formatted forecast.  It may have been that you didn't 'seed' the new host with a forecast.txt file so the PHP script could write it.  Some PHP / file system implementations allow PHP scripts to read/write but not create a file.

It looks like it's working fine now :-)

Best regards,
Ken


Ken:

Hello, thanks for the reply.

Yes,  http://www.anchorageweather.i4host.net/station/anchorageforecast.php is working great, the same file at http://eetee.us/station/anchorageforecast.php is the one that will not refresh forecast.txt (http://eetee.us/station/forecast.txt)

I did include a copy of forecast.txt on the new server.  Unfortunatly, thats the one that won't update :cry:
South of the Tracks, Anchorage, KY

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 8644
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
New php host not working right?!?
« Reply #3 on: August 13, 2006, 09:46:53 PM »
I did a little experiment to see if the cache refreshes by using

http://www.anchorageweather.i4host.net/station/anchorageforecast.php?force=1

The first time, the cache file (forecast.txt) had a timestamp date in the file of

Date: Mon, 14 Aug 2006 01:30:20 GMT


I waited a bit, and tried it with force=1 again, and got a timestamp in forecast.txt of

Date: Mon, 14 Aug 2006 01:30:20 GMT

So, you're correct, the script is not updating the cache file.

Do you have a php.ini file in your root directory of your website.  If so, does it say safe_mode = off ?  If you don't have a php.ini file, create one and put safe_mode = off in the file and upload it and try again with

http://www.anchorageweather.i4host.net/station/anchorageforecast.php?force=1

then examine the cache file at
http://www.anchorageweather.i4host.net/station/forecast.txt
and see if the Date: stamp has changed time.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
New php host not working right?!?
« Reply #4 on: August 13, 2006, 10:48:20 PM »
Quote from: "kenmtrue"
Do you have a php.ini file in your root directory of your website.  If so, does it say safe_mode = off ?  If you don't have a php.ini file, create one and put safe_mode = off in the file and upload it and try again with

http://www.anchorageweather.i4host.net/station/anchorageforecast.php?force=1

then examine the cache file at
http://www.anchorageweather.i4host.net/station/forecast.txt
and see if the Date: stamp has changed time.

Best regards,
Ken


Ken:

Well, it gets more strange;  My host will not let me modify the "root directory'; however, I can add the php.ini files to the /httpdocs directory (the directory on my server where my actual public files are stored).  When I added the php.ini files there - still no luck.

FWIW, the file you mention in your reply above http://www.anchorageweather.i4host.net/station/anchorageforecast.php is for the NON-ADVANCED forecast script.  The ADVANCED script that uses forecast.txt is here:

http://www.anchorageweather.i4host.net/station/advanchorageforecast.php?force=1

Clicking on that WILL update forecast.txt here: http://www.anchorageweather.i4host.net/station/forecast.txt

These files (on anchorageweather.i4host.net) are on my OLD server - they work fine.  But when I copied these files to http://eetee.us/ (my new domain and host), the php files quit refreshing forecast.txt

Again, the files on the NEW server are here:
http://eetee.us/station/advanchorageforecast.php?force=1
and here:
http://eetee.us/station/forecast.txt
These are the ones that won't update.

I know its confusing becasue I have two sets of the same files on two different servers until I can figure out why http://eetee.us/ won't let the php script update forecast.txt
South of the Tracks, Anchorage, KY

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 8644
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
New php host not working right?!?
« Reply #5 on: August 13, 2006, 10:56:39 PM »
Sorry... I was confused. :oops:   Thanks for including the URLs.

Looking at http://eetee.us/station/advanchorageforecast.php?force=1

I see the response headers of:
Server: Apache/2.0.52 (Red Hat)
X-Powered-By: PHP/4.3.9

So maybe it's a file-permissions thing.  Do you have a file control panel with your hoster that can check/set file permissions on individual files?  If so, what's the permission setting on forecast.txt?

Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
New php host not working right?!?
« Reply #6 on: August 14, 2006, 01:26:36 AM »
Quote from: "kenmtrue"

So maybe it's a file-permissions thing.  Do you have a file control panel with your hoster that can check/set file permissions on individual files?  If so, what's the permission setting on forecast.txt?

Ken


Ken:

You nailed it!  It WAS a file permission setting.  I did not even know you could prevent overwriting files.  THANKS a ton for all your help.  Setting the permission correctly also speeds up the page retrievals as well.  All is well. :D

-E
South of the Tracks, Anchorage, KY

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 8644
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
New php host not working right?!?
« Reply #7 on: August 14, 2006, 01:37:47 AM »
Excellent!  

So many differences among hosters.. some let you read/write, some want permissions set on the files first.

Glad you got it working!

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline SLOweather

  • Administrator
  • Forecaster
  • *****
  • Posts: 3457
    • http://www.sloweather.com
New php host not working right?!?
« Reply #8 on: August 14, 2006, 10:16:36 AM »
Linux file permissions always mess me up. Whenever something new I try doesn't work, they are the first thing I check.

 

anything