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 4018) - 28 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

WU Tabular data

Discussion of Ken True's web site templates

Moderator: saratogaWX

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: WU Tabular data

Post by saratogaWX »

I do happen to have a test site on altervista.org ( saratogawx.altervista.org) so I could work out a fix. Note that I'm not currently uploading conditions there, so the conditions displayed are quite out-of-date, but it does serve to test out scripts in the somewhat-restrictive altervista.org environment.

In WU-history-inc.php replace the function

Code: Select all

function getcsvWithoutHanging($url)   {

	$numberOfSeconds=4;    
	error_reporting(0);
	$url = str_replace("http://","",$url);
	$urlComponents = explode("/",$url);
	$domain = $urlComponents[0];
	$resourcePath = str_replace($domain,"",$url);
//	$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);
	$socketConnection = fsockopen('ssl://'.$domain, 443, $errno, $errstr, $numberOfSeconds);	
		$cols = '';
		fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\nUser-agent: $UA\r\nConnection: close\r\n\r\n");
		$rows = 0;
		while (!feof($socketConnection)) {
//			$line = ereg_replace("<br>", "", fgets($socketConnection, 4096));  //One of these gets left in there somehow
			$line = str_replace("<br>", "", fgets($socketConnection, 4096));  //One of these gets left in there somehow	
			$cols[] = explode(",", $line);
		}   
	fclose ($socketConnection);
/*
$cols = file($url);
	
print_r($cols);
exit;	
*/
	for ($i = 0; $i<=11;$i++) {  // Remove the header info that came with download
		array_shift($cols);
	}	
	
	return($cols);
} 
with this function

Code: Select all

function getcsvWithoutHanging($url)   {
	
	$url = str_replace('http://','https://',$url);
    $STRopts = array(
	  'http'=>array(
	  'method'=>"GET",
	  'protocol_version' => 1.1,
	  'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
				"Cache-control: max-age=0\r\n" .
				"Connection: close\r\n" .
				"User-agent: Mozilla/5.0 (WU-history-inc.php saratoga-weather.org)\r\n" .
				"Accept: text/plain,text/html\r\n"
	  ),
	  'https'=>array(
	  'method'=>"GET",
	  'protocol_version' => 1.1,
	  'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
				"Cache-control: max-age=0\r\n" .
				"Connection: close\r\n" .
				"User-agent: Mozilla/5.0 (WU-history-inc.php saratoga-weather.org)\r\n" .
				"Accept: text/plain,text/html\r\n"
	  )
	);
	
   $STRcontext = stream_context_create($STRopts);
   print "<!-- loading $url -->\n";
   $lines = file($url,false,$STRcontext);
   $headerarray = get_headers($url,0);
   $theaders = join("\r\n",$headerarray);
   print "<!-- headers returned: \n".$theaders." -->\n";
   
   // process the returned file
   $cols = array();
   print "<!-- ".count($lines)." lines returned. -->\n";
   foreach ($lines as $i => $line) {
	   $line = str_replace('<br>','',$line);
	   $cols[] = explode(',',$line);
   }
   if (count($cols) > 11) { 
     for ($i = 0; $i<=11;$i++) {  // Remove the header info that came with download
		array_shift($cols);
     }
   }
	
	return($cols);
	
}
which uses the native PHP file() function and avoids the fconnect() issue with HTTPS.

It does work correctly (with the replaced getcsvWithoutHanging function above).

Best regards,
Ken
MeteoBisignano
Posts: 79
Joined: Mon 09 Mar 2015 10:45 am
Weather Station: wh3080
Operating System: windows
Location: Cosenza

Re: WU Tabular data

Post by MeteoBisignano »

saratogaWX wrote:I do happen to have a test site on altervista.org ( saratogawx.altervista.org) so I could work out a fix. Note that I'm not currently uploading conditions there, so the conditions displayed are quite out-of-date, but it does serve to test out scripts in the somewhat-restrictive altervista.org environment.

In WU-history-inc.php replace the function

Code: Select all

function getcsvWithoutHanging($url)   {

	$numberOfSeconds=4;    
	error_reporting(0);
	$url = str_replace("http://","",$url);
	$urlComponents = explode("/",$url);
	$domain = $urlComponents[0];
	$resourcePath = str_replace($domain,"",$url);
//	$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);
	$socketConnection = fsockopen('ssl://'.$domain, 443, $errno, $errstr, $numberOfSeconds);	
		$cols = '';
		fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\nUser-agent: $UA\r\nConnection: close\r\n\r\n");
		$rows = 0;
		while (!feof($socketConnection)) {
//			$line = ereg_replace("<br>", "", fgets($socketConnection, 4096));  //One of these gets left in there somehow
			$line = str_replace("<br>", "", fgets($socketConnection, 4096));  //One of these gets left in there somehow	
			$cols[] = explode(",", $line);
		}   
	fclose ($socketConnection);
/*
$cols = file($url);
	
print_r($cols);
exit;	
*/
	for ($i = 0; $i<=11;$i++) {  // Remove the header info that came with download
		array_shift($cols);
	}	
	
	return($cols);
} 
with this function

Code: Select all

function getcsvWithoutHanging($url)   {
	
	$url = str_replace('http://','https://',$url);
    $STRopts = array(
	  'http'=>array(
	  'method'=>"GET",
	  'protocol_version' => 1.1,
	  'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
				"Cache-control: max-age=0\r\n" .
				"Connection: close\r\n" .
				"User-agent: Mozilla/5.0 (WU-history-inc.php saratoga-weather.org)\r\n" .
				"Accept: text/plain,text/html\r\n"
	  ),
	  'https'=>array(
	  'method'=>"GET",
	  'protocol_version' => 1.1,
	  'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
				"Cache-control: max-age=0\r\n" .
				"Connection: close\r\n" .
				"User-agent: Mozilla/5.0 (WU-history-inc.php saratoga-weather.org)\r\n" .
				"Accept: text/plain,text/html\r\n"
	  )
	);
	
   $STRcontext = stream_context_create($STRopts);
   print "<!-- loading $url -->\n";
   $lines = file($url,false,$STRcontext);
   $headerarray = get_headers($url,0);
   $theaders = join("\r\n",$headerarray);
   print "<!-- headers returned: \n".$theaders." -->\n";
   
   // process the returned file
   $cols = array();
   print "<!-- ".count($lines)." lines returned. -->\n";
   foreach ($lines as $i => $line) {
	   $line = str_replace('<br>','',$line);
	   $cols[] = explode(',',$line);
   }
   if (count($cols) > 11) { 
     for ($i = 0; $i<=11;$i++) {  // Remove the header info that came with download
		array_shift($cols);
     }
   }
	
	return($cols);
	
}
which uses the native PHP file() function and avoids the fconnect() issue with HTTPS.

It does work correctly (with the replaced getcsvWithoutHanging function above).

Best regards,
Ken


Now it works great
Thank you for taking the time to this change
This is my working page :clap: :clap:
MeteoBisignano
Posts: 79
Joined: Mon 09 Mar 2015 10:45 am
Weather Station: wh3080
Operating System: windows
Location: Cosenza

Re: WU Tabular data

Post by MeteoBisignano »

saratogaWX wrote:I do happen to have a test site on altervista.org ( saratogawx.altervista.org) so I could work out a fix. Note that I'm not currently uploading conditions there, so the conditions displayed are quite out-of-date, but it does serve to test out scripts in the somewhat-restrictive altervista.org environment.

In WU-history-inc.php replace the function

Code: Select all

function getcsvWithoutHanging($url)   {

	$numberOfSeconds=4;    
	error_reporting(0);
	$url = str_replace("http://","",$url);
	$urlComponents = explode("/",$url);
	$domain = $urlComponents[0];
	$resourcePath = str_replace($domain,"",$url);
//	$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);
	$socketConnection = fsockopen('ssl://'.$domain, 443, $errno, $errstr, $numberOfSeconds);	
		$cols = '';
		fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\nUser-agent: $UA\r\nConnection: close\r\n\r\n");
		$rows = 0;
		while (!feof($socketConnection)) {
//			$line = ereg_replace("<br>", "", fgets($socketConnection, 4096));  //One of these gets left in there somehow
			$line = str_replace("<br>", "", fgets($socketConnection, 4096));  //One of these gets left in there somehow	
			$cols[] = explode(",", $line);
		}   
	fclose ($socketConnection);
/*
$cols = file($url);
	
print_r($cols);
exit;	
*/
	for ($i = 0; $i<=11;$i++) {  // Remove the header info that came with download
		array_shift($cols);
	}	
	
	return($cols);
} 
with this function

Code: Select all

function getcsvWithoutHanging($url)   {
	
	$url = str_replace('http://','https://',$url);
    $STRopts = array(
	  'http'=>array(
	  'method'=>"GET",
	  'protocol_version' => 1.1,
	  'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
				"Cache-control: max-age=0\r\n" .
				"Connection: close\r\n" .
				"User-agent: Mozilla/5.0 (WU-history-inc.php saratoga-weather.org)\r\n" .
				"Accept: text/plain,text/html\r\n"
	  ),
	  'https'=>array(
	  'method'=>"GET",
	  'protocol_version' => 1.1,
	  'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
				"Cache-control: max-age=0\r\n" .
				"Connection: close\r\n" .
				"User-agent: Mozilla/5.0 (WU-history-inc.php saratoga-weather.org)\r\n" .
				"Accept: text/plain,text/html\r\n"
	  )
	);
	
   $STRcontext = stream_context_create($STRopts);
   print "<!-- loading $url -->\n";
   $lines = file($url,false,$STRcontext);
   $headerarray = get_headers($url,0);
   $theaders = join("\r\n",$headerarray);
   print "<!-- headers returned: \n".$theaders." -->\n";
   
   // process the returned file
   $cols = array();
   print "<!-- ".count($lines)." lines returned. -->\n";
   foreach ($lines as $i => $line) {
	   $line = str_replace('<br>','',$line);
	   $cols[] = explode(',',$line);
   }
   if (count($cols) > 11) { 
     for ($i = 0; $i<=11;$i++) {  // Remove the header info that came with download
		array_shift($cols);
     }
   }
	
	return($cols);
	
}
which uses the native PHP file() function and avoids the fconnect() issue with HTTPS.

It does work correctly (with the replaced getcsvWithoutHanging function above).

Best regards,
Ken


Now it works great
Thank you for taking the time to this change
This is my working page: http://stazionemeteobisignano.it/calabriastation.php
:clap: :clap:
Post Reply