User Tools

Site Tools


uphp:uphp_compiler

This is an old revision of the document!


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 (extension .cgc), which loads and runs much faster after the first time it is created.

When Does the Firmware Compile a Script?

Everytime a uPHP script is run the firmware system automatically checks first to see if there is an available compiled version of the script (it looks in the same directory as the .cgi file for a .cgc file of the same name):

  • If the .cgc file exists, the system loads and runs it. In this case, the .cgi text file is ignored.
  • 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.

The compiler checks for fatal coding errors, skips/ignores comments and creates a much more compact binary version that will run without all of this additional overhead. As this usually needs to be done only once when the .cgi is first executed, subsequent runs of the same script are much, much faster.

Compiling Errors

Fatal coding errors will cause the compiler to quit without creating a .cgc file (syntax errors, unknown functions, included files not found, etc.). A System Log entry is created showing the error and line number where compilation failed. The compiler error is also displayed if the script is run from a browser or the telnet console.

Of course, if there are compiling errors the script cannot be executed until the coding error(s) are fixed.

The File Manager and the Editor

The tools included with the Wattmon OS automatically delete the compiled .cgc file when a .cgi is uploaded or modified, which will trigger compilation the next time the .cgi is run.

Notes

To force compilation of a .cgi script simply delete the corresponding .cgc file and the system will compile it again the next time it is run.

There are a few common situations where recompilation needs to be forced by deleting the .cgc file:

  • If another computer is used to make changes to a .cgi script directly on the SD card (without using the Wattmon OS tools such as File Manager or the Editor).
  • If changes are made to any included files in the .cgi script (see function include).

In these situations, the system will run an existing .cgc without examining the .cgi file (or included files) for changes, so be sure to delete the corresponding .cgc file at the same time.

See Also

include() - Include a file within the current script at the current location

uphp/uphp_compiler.1523643803.txt.gz · Last modified: 2021/09/13 05:56 (external edit)