Next: , Previous: Using The Web Interpreter, Up: Working With Web Applications


5.1.3 Building and Using Compiled Web Applications

In this section we will see how to turn a PHP website into a compiled web application that can be distributed without source code.

Compiling Overview

To compile your website into a web application, call the compiler, pcc with the --fastcgi switch, the name of the application, and a list of all the PHP source files:

     pcc --fastcgi myapp index.php include/foo.inc include/bar.inc

Roadsend PHP will create a binary object file (.o) for each source file in the web application. If you change a source file and wish to rebuild, Roadsend PHP will only recompile those files that have changed. You can force a full rebuild with the --force-rebuild option.

The only files that are necessary when for deployment are the FastCGI stub (myapp.fcgi) and – when linked dynamically, which is done by default – the application library (libmyapp_u.so on Unix, libmyapp_u.dll on Windows). You should copy these two files to your FastCGI binary directory:

     cp myapp.fcgi libmyapp_u.so /usr/lib/cgi-bin/

The web server must now be configured to start the web application and rewrite requests so that they will be sent to it. For an in-depth explanation of configuring the Apache web server to work with compiled web applications, see Deploying on Apache.

Statically Linked Web Applications

Web applications can also be linked statically by adding the --static switch to the compile commandline:

     pcc --static --fastcgi myapp index.php include/foo.inc include/bar.inc

Statically linked web applications do not require any external libraries, as all required code is compiled into the FastCGI binary (myapp.fcgi). This means you do not need to copy the .so or .dll file into the cgi-bin directory when linked statically.

5.1.4 Tips For Listing Source Files

For advanced users of the Unix shell, a convenient way to pass a list of files to pcc is using find in conjunction with back quotes. So, for example, this would compile all files with the extension .php or .inc below the current directory:

     pcc --fastcgi <libname> `find . -name '*.php' -or -name '*.inc'`

Note the use of backticks around the find command.

Another alternative is to pre-generate a list of all files that you want to compile (e.g., into my-file-list.txt), then use the shell to access this list (also using backticks, this time around the cat command):

     pcc --fastcgi <libname> `cat my-file-list.txt`