Welcome to the new home of the Cumulus Support forum.

Latest Cumulus release v1.9.4 (build 1099) - Nov 28 2014
Latest Cumulus MX release - v3.0.0 build 3044 7 December 2018. See the Wiki for download

Saratoga Templates with PHP 7

Discussion of Ken True's web site templates

Moderator: saratogaWX

User avatar
ConligWX
Posts: 734
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis Vantage Pro2 Plus
Operating System: Debian 9.5 Stretch
Location: Bangor, NI
Contact:

Re: Saratoga Templates with PHP 7

Post by ConligWX » Sun 18 Feb 2018 9:57 pm

saratogaWX wrote:All my sites are now running 7.2.2. I did have to upgrade my JPGraph software from 4.0.1 to 4.2.0 to avoid some errata in error_log. Everything else is ok.
Yep just noticed my error.log and seen there was a newer version for 7.2

had another issue though more likely WU again...

WU-Forceast.php error, file was incomplete (23kb). now set the file to 23000bytes or less it will be removed and downloaded again.
Regards Simon

https://www.conligwx.org
https://twitter.com/conligwx
Davis Vantage Pro2 Plus - Meteobrige Nano SD + Saratoga/PWS Templates

User avatar
Mapantz
Posts: 525
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 10 x64 - A beast.
Location: Wareham, Dorset - UK
Contact:

Re: Saratoga Templates with PHP 7

Post by Mapantz » Thu 22 Feb 2018 8:29 pm

I have just upgraded to 7.2.2 as well. I've fixed everything I could find. But, it's just the wuforecast and wuhistory. I only get a notice about 'foreach' on the wuforecast.
The wuhistory has a massive log of errors running in to megabytes.

It just seems to be two things, though.

Code: Select all

[22-Feb-2018 19:22:14 Europe/London] PHP Warning:  Use of undefined constant weekday - assumed 'weekday' (this will throw an Error in a future version of PHP) in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 1990

Code: Select all

[22-Feb-2018 01:01:06 Europe/London] PHP Notice:  A non well formed numeric value encountered in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 2760
Image
Image

User avatar
saratogaWX
Posts: 912
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Saratoga Templates with PHP 7

Post by saratogaWX » Thu 22 Feb 2018 9:50 pm

Are you using WU-History-inc.php - Version 3.4b - 01-Dec-2017 ? If not, download from here

I'm not seeing those errors in my error_log with 7.2.2

User avatar
Mapantz
Posts: 525
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 10 x64 - A beast.
Location: Wareham, Dorset - UK
Contact:

Re: Saratoga Templates with PHP 7

Post by Mapantz » Thu 22 Feb 2018 10:51 pm

Hi Ken

Yes. I updated to that version a few weeks ago.
I cleared the error log and tried the page and I instantly get the errors

Code: Select all

[22-Feb-2018 22:49:30 Europe/London] PHP Notice:  A non well formed numeric value encountered in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 2760
[22-Feb-2018 22:49:30 Europe/London] PHP Warning:  Use of undefined constant weekday - assumed 'weekday' (this will throw an Error in a future version of PHP) in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 1990
Everything on the script works, though.

Are they any specific modules in php 7.2 that need to be checked or unchecked? I left them all default.
Image
Image

User avatar
saratogaWX
Posts: 912
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Saratoga Templates with PHP 7

Post by saratogaWX » Thu 22 Feb 2018 11:03 pm

For the second error, change

Code: Select all

					$data = '<td class = "date">' . substr($tdate[weekday], 0, 3) . '</td><td class = "date"><a href="' . $PHP_SELF . '?ID=' . $WUID . '&month=' . $pmo . '&day=' .$pda . '&year=' . $pyr . '&mode=1&units=' . $units . '">' . $pda . '</a></td>';  //Date/Time
to

Code: Select all

					$data = '<td class = "date">' . substr($tdate['weekday'], 0, 3) . '</td><td class = "date"><a href="' . $PHP_SELF . '?ID=' . $WUID . '&month=' . $pmo . '&day=' .$pda . '&year=' . $pyr . '&mode=1&units=' . $units . '">' . $pda . '</a></td>';  //Date/Time
For the first error.. I don't have a line 2760 in the script. Mine stops at 1564 in WU-History-inc.php so I don't know which line in the script it is complaining about.

I do note that your second error says line 1990 but is really line 996 in WU-History-inc.php Using the same 994 offset would have me looking at (2760-994)=1766 and that is beyond the 1564 in the WU-History-inc.php. So it may be something in your WU-History.php (but mine is only 42 lines long).

Please zip and post both your WU-History-inc.php and WU-History.php pages, and I'll take a look.

User avatar
ConligWX
Posts: 734
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis Vantage Pro2 Plus
Operating System: Debian 9.5 Stretch
Location: Bangor, NI
Contact:

Re: Saratoga Templates with PHP 7

Post by ConligWX » Thu 22 Feb 2018 11:06 pm

Mapantz wrote:I have just upgraded to 7.2.2 as well. I've fixed everything I could find. But, it's just the wuforecast and wuhistory. I only get a notice about 'foreach' on the wuforecast.
The wuhistory has a massive log of errors running in to megabytes.

It just seems to be two things, though.

Code: Select all

[22-Feb-2018 19:22:14 Europe/London] PHP Warning:  Use of undefined constant weekday - assumed 'weekday' (this will throw an Error in a future version of PHP) in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 1990

Code: Select all

[22-Feb-2018 01:01:06 Europe/London] PHP Notice:  A non well formed numeric value encountered in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 2760
I've check my error logs too and cannot find any issues with WU-History.php at all.
saratogaWX wrote: For the first error.. I don't have a line 2760 in the script. Mine stops at 1564 in WU-History-inc.php so I don't know which line in the script it is complaining about.

Same here, mine is much shorter than Mapantz's file.
Regards Simon

https://www.conligwx.org
https://twitter.com/conligwx
Davis Vantage Pro2 Plus - Meteobrige Nano SD + Saratoga/PWS Templates

User avatar
Mapantz
Posts: 525
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 10 x64 - A beast.
Location: Wareham, Dorset - UK
Contact:

Re: Saratoga Templates with PHP 7

Post by Mapantz » Thu 22 Feb 2018 11:21 pm

That's because there's a space between each line of text/code. It always does that after uploading the file.

Here's the correct lines:

Code: Select all

[22-Feb-2018 23:20:49 Europe/London] PHP Notice:  A non well formed numeric value encountered in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 1381
[22-Feb-2018 23:20:49 Europe/London] PHP Warning:  Use of undefined constant weekday - assumed 'weekday' (this will throw an Error in a future version of PHP) in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 996
Second line fixed, Ken. :)

Code: Select all

	$newdate = mktime (0,0,0,$month,$nday,$year);
Image
Image

User avatar
saratogaWX
Posts: 912
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Saratoga Templates with PHP 7

Post by saratogaWX » Thu 22 Feb 2018 11:34 pm

Ahh.. that explains the line count issue...

Line 1381 is

Code: Select all

	$newdate = mktime (0,0,0,$month,$nday,$year);
which is inside

Code: Select all

function AddDate ( $month, $day, $year, $numdays) {
	$nday = $day + $numdays;
	$newdate = mktime (0,0,0,$month,$nday,$year);
	return getdate($newdate);
}	
The AddDate function is invoked many places with calls like

Code: Select all

	$ndate = AddDate($mo, $da, $yr, -1);
with the last argument varying (but always numeric).
One entry at line 992 has

Code: Select all

					$tdate = AddDate($pmo, $pda, $pyr, 0); // just to get the name of the day
and the arguments come from

Code: Select all

			for ($col=0; $col<$columns; $col++) {
				$data = $csvarray[$row][$col];      
				if ($col == 0) {
					$pmo = substr($data, 5, 2);
					$pda = substr($data, strrpos($data,"-")+1, 2);
					$pyr = substr($data, 0, 4);
					$tdate = AddDate($pmo, $pda, $pyr, 0); // just to get the name of the day
since the error only comes once (on your system), I suspect it may be the first entry in your CSV that has a different date format than expected.

Try changing

Code: Select all

					$tdate = AddDate($pmo, $pda, $pyr, 0); // just to get the name of the day
to

Code: Select all

 print "<!-- data='$data' pmo='$pmo' pda='$pda' pyr='$pyr' -->\n";
					$tdate = AddDate($pmo, $pda, $pyr, 0); // just to get the name of the day
print "<!-- tdate='$tdate' -->\n";
and it should embed HTML comments in the output that show up with a view-source of the page.

User avatar
Mapantz
Posts: 525
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 10 x64 - A beast.
Location: Wareham, Dorset - UK
Contact:

Re: Saratoga Templates with PHP 7

Post by Mapantz » Thu 22 Feb 2018 11:38 pm

Changed that..

Code: Select all

[22-Feb-2018 23:37:09 Europe/London] PHP Notice:  A non well formed numeric value encountered in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 1383
[22-Feb-2018 23:37:09 Europe/London] PHP Notice:  Array to string conversion in /home/warehamw/public_html/cumulus/wuhistory/WU-History.php on line 994
Image
Image

User avatar
saratogaWX
Posts: 912
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Saratoga Templates with PHP 7

Post by saratogaWX » Thu 22 Feb 2018 11:51 pm

What is the URL to the WU-History.php and WU-History-inc.php pages?

User avatar
ConligWX
Posts: 734
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis Vantage Pro2 Plus
Operating System: Debian 9.5 Stretch
Location: Bangor, NI
Contact:

Re: Saratoga Templates with PHP 7

Post by ConligWX » Thu 22 Feb 2018 11:54 pm

saratogaWX wrote:What is the URL to the WU-History.php and WU-History-inc.php pages?
https://warehamwx.co.uk/cumulus/wuhistory/wuhistory.php
Regards Simon

https://www.conligwx.org
https://twitter.com/conligwx
Davis Vantage Pro2 Plus - Meteobrige Nano SD + Saratoga/PWS Templates

User avatar
saratogaWX
Posts: 912
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Saratoga Templates with PHP 7

Post by saratogaWX » Fri 23 Feb 2018 12:09 am

I don't see the extra debugging code in the output (but I do see it in your source), so that instance is not invoked.

It must be one of the other AddDate() calls that is throwing the error.

We fixed the PHP Warning message. The PHP Notice: messages are a nuisance but not harmful. Given that your instance of the script is throwing the Notice errata (but mine is not on PHP 7.2.2 despite having Notice enabled), I don't think I can help further in isolating the issue.. Sorry!

User avatar
Mapantz
Posts: 525
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 10 x64 - A beast.
Location: Wareham, Dorset - UK
Contact:

Re: Saratoga Templates with PHP 7

Post by Mapantz » Fri 23 Feb 2018 12:29 am

No problems Ken. Like you say, at least the warning has gone. :)

I put

Code: Select all

// Turn off all error reporting
error_reporting(0);
At the top of the page.

Thank you for your help.
Image
Image

User avatar
ConligWX
Posts: 734
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis Vantage Pro2 Plus
Operating System: Debian 9.5 Stretch
Location: Bangor, NI
Contact:

Re: Saratoga Templates with PHP 7

Post by ConligWX » Tue 27 Feb 2018 8:09 am

Hi Ken

I noticed then mesonet page on my site now has an error this morning.

Code: Select all

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /path/to/htdocs/weather/mesonet-map-genhtml-inc.php on line 208

Code: Select all

	Line 208: while (list($key, $val) = each($Stations)) { 
	Line 241: while (list($key, $val) = each($Stations)) {
The PHP Manual says that the each() function has been deprecated as of PHP 7.2.0 this means there maybe more than just this instance of each affecting in other webpages.

so should this be correct?

Code: Select all

while (list($key, $val) = each($Stations)) { 
change to:

Code: Select all

foreach($Stations as $key => $val) {
Last edited by ConligWX on Tue 27 Feb 2018 5:24 pm, edited 1 time in total.
Regards Simon

https://www.conligwx.org
https://twitter.com/conligwx
Davis Vantage Pro2 Plus - Meteobrige Nano SD + Saratoga/PWS Templates

User avatar
saratogaWX
Posts: 912
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Saratoga Templates with PHP 7

Post by saratogaWX » Tue 27 Feb 2018 5:00 pm

Hi Simon,

Yes, that is a good fix for the Deprecated issue. Comments at the PHP docs page even indicate that using foreach is much faster than the while..each() so thats a good thing.

Thanks for finding this.. I'll do an update (and look for more instances in my code).

Post Reply