Php webtags: Difference between revisions

1,758 bytes added ,  09:28, 25 April 2020
m
Line 21: Line 21:
= Using PHP script =
= Using PHP script =


If you adopt PHP Hypertext Processing on your web site; there are two main approaches:
If you adopt PHP Hypertext Processing (other alternatives described below) on your web site; there are two main approaches:
#Either simply [[Customised_templates|customise]] the standard template pages by adding some PHP script that will be parsed (interpreted) after the template processed by Cumulus has been uploaded to your web server, but before the resulting HTML is sent to the browser.
#Either simply [[Customised_templates|customise]] the standard template pages by adding some PHP script that will be '''parsed''' (interpreted) after the '''template processed by Cumulus''' has been uploaded to your web server, but before the resulting HTML is sent to the browser.
#Or write a web page including PHP code that does not need to be processed by Cumulus. To get the information that Cumulus provides, all your new pages can "'''include'''" (if you want the page to fail without that cumulus derived information - use "''require''" instead) one, or more, PHP script file that Cumulus '''has''' previously  processed. In that processing all the [[webtags]] values were assigned to PHP variables.  This second approach is more efficient for those using PHP on their website as the actual web pages are produced from PHP scripts on the web server and do not need to be uploaded each time the numbers they output change. In general each full HTML structure definition for a web page is a far larger uploading burden than the file containing the variables.
#Or write a web page including PHP code that does not need to be processed by Cumulus. To get the derived value information that Cumulus provides, all your new pages can "'''include_once'''" (if you want the page to fail without that cumulus derived information - use "''require_once''" instead) one, or more, PHP script file(s) that Cumulus '''has''' previously  processed. In that processing all the [[webtags]] values were assigned to PHP variables.  This second approach is more efficient for those using PHP on their website as the actual web pages are produced from PHP scripts on the web server and do not need to be uploaded each time the numbers they output change. After all having to upload multiple full HTML structure definitions for all web pages is a far larger uploading burden than uploading just the files containing the variables at their appropriate frequency.


This article will first address some of the complications that make providing such a variable assigning script more difficult than you might expect. The multiple complications imply that nobody can write a ready made single template script that will suit everyone. It also means if you are considering producing your own set of scripts to suit what you might do on your web site, there is quite a lot to think about. Next this article has links to a number of ready made fairly simple templates explaining which versions of Cumulus they will work with. After that this article helps you to produce your own set of templates, while it also describes some alternative approaches.
This article will first address some of the complications that make providing such a variable assigning script more difficult than you might expect. The multiple complications imply that nobody can write a ready made single template script that will suit everyone. It also means if you are considering producing your own set of scripts to suit what you might do on your web site, there is quite a lot to think about. Next this article has links to a number of ready made fairly simple templates explaining which versions of Cumulus they will work with. After that this article helps you to produce your own set of templates, while it also describes some alternative approaches.


== Web tag Complications ==
== Web tag Complications ==
Don't think that making all web tags available as PHP variables on your web server is easy, let us see why.
 
There is a widespread expectation that others can produce a template file that will give you exactly what you want to use on your PHP web pages, this is just not realistic as there are multiple permutations of many web tags and you cannot count on anyone else selecting the permutations you want to use. Don't think that making '''all web tags''' available as PHP variables on your web server is easy, let us see why.


=== Version specific tags ===
=== Version specific tags ===


This should be obvious, but people choosing ready made scripts often get caught out by this, expecting their script to give them web tags added in latest release. Each script provided by someone will make its selection of what PHP variables to set based on those tags and parameters available when the script was generated. Individual web tags are added as releases progress, so very few were available in early versions of Cumulus 1, compared to latest versions. When Cumulus MX was first released it did not include all web tags available in the final release of Cumulus 1, now in its releases MX has many more web tags than Cumulus 1. Also the input or output parameters available may change at a particular version.
*This should be obvious, but people choosing ready made scripts often get caught out by this, expecting their script to give them web tags added in latest release. Each script provided by someone will make its selection of what PHP variables to define based on those tags and parameters available in the version they are using when their script was generated.  
*Individual web tags are added as releases progress, so very few were available in early versions of Cumulus 1, compared to latest versions. When Cumulus MX was first released it did not include all web tags available in the final release of Cumulus 1, now in its releases MX has many more web tags than Cumulus 1.  
*Also the input or output parameters available may change at a particular version, adding permutations that were not available when any particular script was produced.


=== static or rarely changing content===
=== static or rarely changing content===
Line 41: Line 44:
*Many tags that represent extreme records might change any time during the day, but those that represent extremes in a particular month can only be updated if it currently is that month.
*Many tags that represent extreme records might change any time during the day, but those that represent extremes in a particular month can only be updated if it currently is that month.


It does not make for efficient use of resources if you make Cumulus process every web tag each time Cumulus does a real time update (which on some sites is every second) and then every upload has to contain a long file defining all those PHP variables that have not changed as well as the few that have chnaged. So although this article has links to many single ready made scripts assigning every single Cumulus web tag to a PHP variable, it actually makes better sense to have multiple scripts, each processed only when the content might change for the tags in that script.
It does '''not''' make for efficient use of ''processing and uploading resources'' if you make Cumulus process '''every web tag''' each time Cumulus does a '''real time update''' (which on some sites is every second) and then '''every upload''' has to contain a long file defining all those PHP variables that have ''not changed'' as well as the few that have been updated.  


=== station specific tags ===
So although this article has links to many single ready made scripts assigning every single Cumulus web tag to a PHP variable, it actually makes better sense to have multiple scripts, each processed only when the content might change for the tags in that script.


*Remember some web tags are specific to particular station types and may not return any useful information for your station. For example <code>$light=<#Light>;</code> is a value that only applies to those Fine Offset stations that have a solar sensor and not to any other make or type (although note that stations manufactured by Fine Offset are sold by a number of different companies who brand those stations with their own name, and in the USA the Fine Offset brand name itself is never used). Equally Evapotranspiration and storm rain is specific to Davis models.
=== station and/or sensor specific tags ===
 
*Remember some web tags are specific to particular station types and may not return any useful information for your station.  
*For example <code>$light=<#Light>;</code> is a value that only applies to those Fine Offset stations that have a solar sensor and not to any other make or type (although note that stations manufactured by Fine Offset are sold by a number of different companies who brand those stations with their own name, and in the USA the Fine Offset brand name itself is never used).  
*Equally Evapotranspiration and storm rain is specific to Davis models.
*If you look at a list of web tags, you may be surprised by how long the list is of web tags that are specific to either particular station types or to set-ups with particular sensors. In general these sensors will be reporting values that do need to be updated at real time interval, if you do have that sensor.  


Some ready made scripts will omit station specific tags, some will include them. Check if any script you choose to use includes the tags you want, and edit out any you can't use.
Some ready made scripts will omit station specific tags, some will include them. Check if any script you choose to use includes the tags you want, and edit out any you can't use.
Line 52: Line 60:


*In early versions of Cumulus, its web tags did not take parameters and it was easy to assign each web tag to a variable that any data transfer approach could use;
*In early versions of Cumulus, its web tags did not take parameters and it was easy to assign each web tag to a variable that any data transfer approach could use;
*From version 1.9.3 various web tags (such as "Recent History") always take input parameters, others (like those reporting times and/or dates) can take output parameters.  
*From version 1.9.1, many web tags (like those reporting times and/or dates whether directly or as time/date stamps) can take output parameters that format how the date (if available) and time (if available) are output.
**There are now a vast number of possible combinations for such parameters in many web tags, and it would be in-efficient for large numbers of those combinations to be generated whether needed or not.  
** The number of different ways to specify a date or time is quite a lot, apply that to every web tag that can take output parameters and one could define perhaps a thousand different PHP variables!
*From version 1.9.3 (build 1033) some web tags (initially just "Recent History") always require input parameters, so any script turning web tags into script variables must choose which value to use for the input parameter and how many alternatives with different values for input parameter to include.  
**For each Recent History web tag there are more than 605 thousand different combinations that could be specified. Nobody wants to include all of those in any script they write as that is over 9 million PHP variables to define!
 
*There are now a vast number of possible combinations for such parameters in many web tags, and it would be in-efficient for large numbers of those combinations to be generated whether needed or not.  
**Consequently anyone devising a single template file has to guess which parameters are most useful, and in most of the ready made templates no parameters are included so a vast amount of the information accessible for a web page generated directly from a template file is not available for web pages generated from scripts on your web server.
**Consequently anyone devising a single template file has to guess which parameters are most useful, and in most of the ready made templates no parameters are included so a vast amount of the information accessible for a web page generated directly from a template file is not available for web pages generated from scripts on your web server.
**Because of this 'guessing'; '''do not assume''' that a file from some one else, will meet your requirements ''out of the box'', you must understand the script language and be prepared to edit the file supplied into one that meets your own requirements.
**Because of this 'guessing'; '''do not assume''' that a file from some one else, will meet your requirements ''out of the box'', you must understand the script language and be prepared to edit the file supplied into one that meets your own requirements.
5,838

edits