This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
uphp:uphp_compiler [2018/04/13 18:10] jeff created: linked to from include() |
uphp:uphp_compiler [2021/09/13 05:57] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
======The uPHP Compiler====== | ======The uPHP Compiler====== | ||
- | uPHP scripts are written by humans as text files (extension .cgi). But to speed things up the Wattmon system actually executes a compiled binary version | + | uPHP scripts are written by humans as text files. But to speed things up the [[hardware: |
+ | |||
+ | Mainline PHP is not a compiled language. However, uPHP is designed to run with limited memory constraints and uses a compiler to reduce requirements and speed loading and execution of scripts. Compilation is performed automatically by the firmware "in the background" | ||
+ | |||
+ | If you have spent some time looking at the files on the [[hardware: | ||
+ | |||
+ | This page provides some practical information on when and how the uPHP Compiler works, of interest to those who are customizing the [[hardware: | ||
====When Does the Firmware Compile a Script?==== | ====When Does the Firmware Compile a Script?==== | ||
- | Everytime | + | Every time a uPHP script |
- | * If the .cgc file exists, the system loads and runs it. In this case, the .cgi text file is ignored. | + | * If the .cgc file already |
- | * If the .cgc file does not exist, the compiler checks the .cgi for any fatal coding errors, writes the compiled .cgc file to disk, and runs it. | + | * If the .cgc file does not exist, the compiler checks the .cgi for any fatal coding errors. If no compiling errors are found it writes the compiled .cgc file to disk, then runs it. |
- | The compiler checks for fatal coding errors, skips/ | + | The compiler |
====Compiling Errors==== | ====Compiling Errors==== | ||
Line 18: | Line 24: | ||
Of course, if there are compiling errors the script cannot be executed until the coding error(s) are fixed. | Of course, if there are compiling errors the script cannot be executed until the coding error(s) are fixed. | ||
+ | |||
+ | ====Compilation of Included Scripts==== | ||
+ | |||
+ | A uPHP script can, of course, be written and given a file name with any type or extension, but it will not be directly executable. (The uPHP compiler only directly evaluates files of type " | ||
+ | |||
+ | However, there is a practical reason for writing uPHP scripts in other file types as they can be " | ||
+ | |||
+ | If any type of file is included in a .cgi script, the compiler evaluates the code contained in it and inserts it into the .cgc compiled version of //the " | ||
+ | |||
+ | For more information see function [[.functions: | ||
+ | |||
+ | ====Conditional Compilation for Included Scripts==== | ||
+ | |||
+ | If an included file does not yet exist the compiler will fail with a fatal error unless you use a conditional test for the [[.functions: | ||
+ | |||
+ | <code php> | ||
+ | if (file_exists(" | ||
+ | </ | ||
+ | |||
+ | When the included file is later created recompilation will occur and a new .cgc is created when //the " | ||
+ | |||
+ | Here is an example from the Wattmon OS file ''/ | ||
+ | |||
+ | <code php> | ||
+ | include("/ | ||
+ | $packages=getPackageList(); | ||
+ | $keys=array_keys($packages); | ||
+ | for ($vi=0; | ||
+ | if ($packages[$keys[$vi]]==2) { // active, enabled | ||
+ | log(" | ||
+ | if (file_exists("/ | ||
+ | include("/ | ||
+ | if (function_exists($keys[$vi]." | ||
+ | call_user_func($keys[$vi]." | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In this example ''/ | ||
====The File Manager and the Editor==== | ====The File Manager and the Editor==== | ||
Line 29: | Line 76: | ||
There are a few common situations where recompilation needs to be forced by deleting the .cgc file: | There are a few common situations where recompilation needs to be forced by deleting the .cgc file: | ||
- | * Another | + | * If another |
- | * Changes | + | * If changes |
+ | |||
+ | In these situations, the system will run an existing .cgc without examining the .cgi text file or included file(s) for changes, so be sure to delete the corresponding .cgc file at the same time. (Note from the author of this page: I learned this "the hard way" because I didn't have this documentation at the time, which led to the creation of this page.) | ||
+ | |||
+ | In most cases, an easy way to delete compiled versions is to use the dropdown menu option "Clear Cache" (in the header of most displayed pages on the [[hardware: | ||
+ | |||
+ | {{ 20180420_130046_screenshot.jpg? | ||
- | In these situations, the system will run an existing | + | "Clear Cache" deletes all .cgc files in the "/" |
- | ====See Also==== | + | ====Also |
[[.functions: | [[.functions: | ||