Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4017) - 17 March 2024

Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

Saratoga Templates with PHP 7

Discussion of Ken True's web site templates

Moderator: saratogaWX

User avatar
ConligWX
Posts: 1570
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis vPro2+ w/DFARS + AirLink
Operating System: Ubuntu 22.04 LTS
Location: Bangor, NI
Contact:

Re: Saratoga Templates with PHP 7

Post by ConligWX »

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 - @conligwx
Davis Vantage Pro2 Plus with Daytime FARS • WeatherLink Live • Davis AirLink • PurpleAir •

Image
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: Saratoga Templates with PHP 7

Post by Mapantz »

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
User avatar
saratogaWX
Posts: 1170
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 »

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
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: Saratoga Templates with PHP 7

Post by Mapantz »

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
User avatar
saratogaWX
Posts: 1170
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 »

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: 1570
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis vPro2+ w/DFARS + AirLink
Operating System: Ubuntu 22.04 LTS
Location: Bangor, NI
Contact:

Re: Saratoga Templates with PHP 7

Post by ConligWX »

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 - @conligwx
Davis Vantage Pro2 Plus with Daytime FARS • WeatherLink Live • Davis AirLink • PurpleAir •

Image
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: Saratoga Templates with PHP 7

Post by Mapantz »

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
User avatar
saratogaWX
Posts: 1170
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 »

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.
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: Saratoga Templates with PHP 7

Post by Mapantz »

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
User avatar
saratogaWX
Posts: 1170
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 »

What is the URL to the WU-History.php and WU-History-inc.php pages?
User avatar
ConligWX
Posts: 1570
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis vPro2+ w/DFARS + AirLink
Operating System: Ubuntu 22.04 LTS
Location: Bangor, NI
Contact:

Re: Saratoga Templates with PHP 7

Post by ConligWX »

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 - @conligwx
Davis Vantage Pro2 Plus with Daytime FARS • WeatherLink Live • Davis AirLink • PurpleAir •

Image
User avatar
saratogaWX
Posts: 1170
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 »

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!
Mapantz
Posts: 1774
Joined: Sat 17 Dec 2011 11:55 am
Weather Station: Davis Vantage Pro2
Operating System: Windows 11 x64
Location: Dorset - UK
Contact:

Re: Saratoga Templates with PHP 7

Post by Mapantz »

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
User avatar
ConligWX
Posts: 1570
Joined: Mon 19 May 2014 10:45 pm
Weather Station: Davis vPro2+ w/DFARS + AirLink
Operating System: Ubuntu 22.04 LTS
Location: Bangor, NI
Contact:

Re: Saratoga Templates with PHP 7

Post by ConligWX »

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 - @conligwx
Davis Vantage Pro2 Plus with Daytime FARS • WeatherLink Live • Davis AirLink • PurpleAir •

Image
User avatar
saratogaWX
Posts: 1170
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 »

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