You are on page 1of 21

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

NuSphere Nu-Coder 2.0 User Guide


Contacting NuSphere
Postal Address:
NuSphere Corporation 465 S. Meadows parkway # 20-154 Reno, Nevada 89521 USA

Phone: (859) 288-4505 Fax: (267) 590-8538 On the web:


Please use Contact Us form at http://shop.nusphere.com/contact_us/index.php

Email: sales@ nusphere.com

Useful Links
FAQ and Support Forums: http://support.nusphere.com/index.php NuSphere Home Page: http://www.nusphere.com NuSphere PhpED (PHP IDE) product page:
http://www.nusphere.com/products/phped.htm

NuSphere PhpDock (PHP Deployment solution):


http://www.nusphere.com/products/phpdock.htm

Errors, Omissions and Suggestions


NuSphere spares no effort in preparation and inspection of this User Guide. In an unlikely event should you discover any error or if you have any suggestions or comment, please dont hesitate to contact us using Contact Us form at http://shop.nusphere.com/contact_us/index.php. We DO listen.

-1-

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

Content

NuSphere Nu-Coder 2.0.................................................................................................................... - 1 User Guide ........................................................................................................................................ - 1 1 2 Content ............................................................................................................................................. - 2 Introduction...................................................................................................................................... - 4 2.1 2.2 2.3 3 3.1 3.2 What is Nu-Coder? ....................................................................................................................... - 4 Why do you need to encode PHP Applications? .......................................................................... - 4 Protecting PHP files with Nu-Coder .............................................................................................. - 4 Command Examples .................................................................................................................... - 5 Nu-Coder and PhpExpress support for PHP 4 and for PHP 5 ...................................................... - 5 -

User Guide Notation........................................................................................................................ - 5 -

Nu-Coder and PhpExpress difference ............................................................................................... - 5 Examples used in this User Guide..................................................................................................... - 5 4 5 Typical usage of Nu-Coders encoder and license manager ....................................................... - 6 Quick Start ....................................................................................................................................... - 7 5.1 5.2 6 6.1 6.2 7 7.1 7.2 7.3 7.4 7.5 7.6 Encoding PHP project using Nu-Coder Command Line Interface................................................. - 7 Deploying the files encoded with Nu-Coder.................................................................................. - 8 Functionality provided by Nu-Coder.............................................................................................. - 9 Interfacing with Nu-Coder ............................................................................................................. - 9 How to encode PHP files using Nu-Coder Command Line Interface ......................................... - 10 How to encode single PHP file ................................................................................................... - 10 How to encode PHP files in the entire directory.......................................................................... - 10 How to control the process of encoding of PHP files .................................................................. - 11 How to use License Manager generated licenses when encoding PHP files.............................. - 12 Examples:................................................................................................................................... - 12 -

Nu-Coder Features Overview ......................................................................................................... - 9 -

Nu-Coder Command Line Interface ............................................................................................. - 10 Syntax ............................................................................................................................................. - 10 -

Example #1...................................................................................................................................... - 12 Example #2...................................................................................................................................... - 13 Example #3...................................................................................................................................... - 13 Example #4...................................................................................................................................... - 13 Example #5...................................................................................................................................... - 13 Example #6...................................................................................................................................... - 13 8 Nu-Coder License Manager .......................................................................................................... - 14 8.1 8.2 8.3 8.4 How to generate License Manager Licenses using Nu-Coder Command Line Interface............ - 14 How to load license..................................................................................................................... - 15 How to handle expired or invalid license..................................................................................... - 16 Examples:................................................................................................................................... - 16 Syntax ............................................................................................................................................. - 14 -

Example #1...................................................................................................................................... - 16 Example #2...................................................................................................................................... - 16 9 Deploying Encoded PHP files with NuSphere PhpExpress ....................................................... - 18 9.1 Overview of NuSphere PhpExpress ........................................................................................... - 18 -

-2-

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

9.2 9.3 9.4 10

How to deploy NuSphere PhpExpress........................................................................................ - 18 How to use API provided by NuSphere PhpExpress to work with Nu-Coder.............................. - 18 How to monitor PHP Cache implemented by NuSphere PhpExpress ........................................ - 19 -

Deploying Encoded PHP files with NuSphere PhpDock ............................................................ - 21 -

-3-

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

2
2.1

Introduction
What is Nu-Coder? Although the open-source distribution model is widely adopted by the PHP development community and works very well in many cases; encoding and protection of PHP source code is often critical to the distribution of commercial PHP applications. Nu-Coder is a powerful PHP Encoder that enables PHP developers to protect their PHP code from tempering and unauthorized copying. Nu-Coder converts the source code of PHP Script into compiled PHP bytecodes for both accelerated runtime performance and maximum security. When License Manager is used the content of the file gets additionally encrypted increasing the level of protection. NuSphere Nu-Coder consists of two components providing a dual layer of protection for PHP applications: PHP Encoder executable named nu-coder (or nu-coder.exe for Windows) License Manager executable named nu-licgen ( or nu-licgen.exe for Windows)

Nu-Coders PHP Encoder converts the source code of PHP Script into compiled PHP bytecodes for both accelerated runtime performance and maximum security. These scripts can be loaded and run with PhpExpress - NuSphere Free PHP accelerator that provides support for loading of PHP files encoded with Nu-Coder - NuSphere PHP Encoder and also speeds up the execution of both encoded and regular PHP files. Encoded PHP scripts are known to run at up to 120% faster than open-source scripts. Nu-Coders License Manager helps you manage the distribution of PHP applications by generating license keys that can be required by encoded files to run. Using License Manager you can create trial and demo versions of PHP applications without any code changes, restrict the IP or the host name or host id where your application can run and much more

2.2

Why do you need to encode PHP Applications? Piracy Protection: PHP developers and Independent Software Vendors (ISVs) can safely distribute their source code, knowing that their intellectual property is protected Reduced support burden: Since technical support personnel will be able to rule out PHP source code modifications Enhanced compliance: Enterprise customers can enforce internal policies and easily provide the support for a company's PHP Applications.

2.3

Protecting PHP files with Nu-Coder You can encode PHP files using Nu-Coder's powerful command line interface or from within the user interface provided by NuSphere PhpED. Your users will need NuSphere PhpExpress to deploy and run the encoded PHP Files. PhpExpress is available for free download and distribution. PhpExpress is also built in NuSphere PhpDock, which now fully supports deployment of encoded PHP applications. PhpExpress also provides API in form of PHP functions that can be called to retrieve various information.

-4-

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

User Guide Notation


This section explains certain syntax conventions used in this User Guide.

3.1

Command Examples Command line text in the User Guide is printed in monospace bold font. Command examples are printed in the form:

nu-coder.exe [options] source-directory target-directory


Or to illustrate command usage and output, as

prompt> nu-coder -v NuSphere PHP Encoder Nu-Coder 2.0.0 Copyright (c) 2005-2008 NuSphere Corp.
Or similar with License Manager

prompt> nu-licgen -v NuSphere Nu-Coder license generator 2.0.0 Copyright (c) 20052008 NuSphere Corp.
Shell input is shown in bold, and program output is plain. prompt> is an example shell prompt for command entry but this may be different on your own system. 3.2 Nu-Coder and PhpExpress support for PHP 4 and for PHP 5

Nu-Coder and PhpExpress difference


Nu-Coder supports encoding of the scripts written in PHP versions 4.3, 4.4, 5.0, 5.1 and 5.2. PHP scripts written on earlier versions of PHP and encoded with Nu-Coder can also be deployed on any later version of PHP interpreter with the help of PhpExpress. Unlike many other PHP Encoders, Nu-Coder can encoder PHP files with special provisions for intermediate versions with the use of c parameter. For example using php encoder with option c 5.1 will result in encoding taking in account special features available in PHP 5.1 and not just PHP 5.0

Examples used in this User Guide


The PHP version of the script being encoded with Nu-Coder can be specified by passing c parameter followed by version number to Nu-Coder Command Line Interface. For example, the following line will invoke the encoding for PHP 4.3 script file.php, storing the output in the file file_enc.php:

nu-coder.exe -c 4.3 file.php file_enc.php


-c is not a required parameter, if omitted the script will be encoded with PHP 5.1. For simplicity in this document we will omit c parameter in the most of the examples. Therefore these examples will illustrate how the program should be used if encoding a PHP 5.1 project to ensure that your encoded scripts will run on PHP 5.1 servers. If the project is on a different version of PHP, the c parameter should be used explicitly to specify the version to the Encoder.

-5-

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

Typical usage of Nu-Coders encoder and license manager


In a typical scenario your files will be encoded on same machine where you do PHP development, i.e. Windows box. If you are also using PhpED NuSpheres PHP IDE you will be able to encode PHP files using Graphic User Interface on the same machine with PhpED. Encoded files are usually packaged and placed on the server from where they can be downloaded by your customers for either evaluation trial or purchase. However, the License files usually need to be generated on the server at the time when the customers request to download is received. For this purpose NuSphere supplies License Manager for all major platforms, including *BSD/x86 and x86_64, Linux/x86 and x86_64, Windows x86 and x64,Solaris/x86, x86_64 and Sparc. There are two the most commonly used ways to generate the license: License that expires after certain time interval or on certain date typically used for trial versions and demos License that doesnt expire in time but only allow execution of PHP scripts on certain identified hardware or on specified IP address or network segment Please consult this manual for the ways to load, work and do the error handling of the Licenses generated by Nu-Coders License Manager. Note: The encoding and deployment of the files described here is only what we consider typical scenario. NuSphere provides Nu-Coder binaries for all major platforms to support various usages of PHP files encryption and encoding.

-6-

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

Quick Start
This chapter introduces some of the most common features of the Command Line Interface to Nu-Coder PHP Encoder, with quick-start examples for typical scenarios. For PhpED users, it also describes the PhpED GUI for Nu-Coder. Detailed description of NuCoder CLI and PhpED GUI for Nu-Coder is given in subsequent chapters of this User Guide.

5.1

Encoding PHP project using Nu-Coder Command Line Interface You can encode php files in the entire project using directory processing mode of NuCoder. In the following example we will assume that your Project root (or top) Windows directory is C:\Program Files\nusphere\project-dir\web. To encode the files in C:\Program Files\nusphere\project-dir\web and all of it subdirectories you need to: Install NuSphere Nu-Coder Open a Command Window (Run->cmd) Type at the prompt:

prompt> cd C:\Program Files\nusphere\project-dir


To run Nu-Coder in directory processing mode and generate output of encoded files in directory C:\Program Files\nusphere\project-dir\web-encoded type:

prompt> nu-coder r web web-encoded


The program will recursively traverse all files in directory C:\Program Files\nusphere\project-dir\web and its subdirectories and generate encoded files in C:\Program Files\nusphere\project-dir\web-encoded with the same directory structures and file names. Illustration below shows the output of the Nu-Coder running:

-7-

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

5.2

Deploying the files encoded with Nu-Coder At this point you can deploy encoded PHP files stored in the directory C:\Program Files\nusphere\project-dir\web-encoded with any PHP interpreter running PhpExpress NuSphere Free PHP loader and accelerator that provides support for encoded files and also speeds up the execution of regular PHP files. Simple procedure of installing PhpExpress is described in section 8.2 of this User Guide. Note: If an attempt is made to execute the files encoded with Nu-Coder on the system without PhpExpress installed, the system will search for PhpExpress module in the web folders under Document Root (recursively) and try to load it if found. If PhpExpress is not found there as well, then the system will display a warning message to the user, saying that PhpExpress is not installed and referring the User to PhpExpress download website. Please note that you can also: Use version-1.4 compatible header (--nodl command line argument) in this case the search for PhpExpress wont be performed and the error will be generated immediately Encode the file without the header using --noheader command line option. In this case the server will use the default file handler to serve the encoded script Use custom header (--header command line option) and take control over the handling of this situation

-8-

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

6
6.1

Nu-Coder Features Overview


Functionality provided by Nu-Coder The features include: Command Line Encoder for Windows Graphical and Command Line Encoder for Windows License Manager for generation of license files for encoded PHP Scripts on all major platforms including Linux, Windows, Mac OS and Unix Deployment on all major platforms including Linux, Windows and Unix Encoding PHP Scripts with compiled bytecodes Addition Strong Encryption of PHP scripts with License Manager Better execution performance than regular PHP files Support for both PHP versions 4 and 5 Tight integration with all NuSphere products, such as PhpED and PhpDock

6.2

Interfacing with Nu-Coder NuSphere provides two different interfaces with Nu-Coder: Command Line Interface to a standalone Nu-Coder Graphical User Interface to Nu-Coder from PhpED, NuSphere PHP IDE Both interfaces allow the user to pass various parameters to the encoder to control the way PHP Sources are compiled into bytecodes and the creation of output files. Using either of these interfaces you can: Specify the PHP version of the files that are being encoded Encode and protect PHP files in the entire given directory and its sub-directories Encode single PHP file and save results into output file. Tell Nu-Coder to create output files name by appending given extension at the end of the source file name Overwrite the source file with encoded content Perform Syntax check only and not produce any encoded content In directory processing mode, encode only files with certain extensions (defaults are php and inc) Copy all non-php files into target directory Ignore errors and continue encoding Turn off support for short php tags <? ?> Turn on support for asp style php tags <% %> Keep extended information for php debugger and php profiler Preserve line numbers information Preserve and not strip php-doc comments, useful for reflection Create license files required to run encoded PHP scripts Skip encoding of certain files and folders or encode them but not protect with the license Obfuscate the source (change the names of the variables) Specify the script to be called to handle an error (e.g. expired license) Changed the files headers

-9-

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

Nu-Coder Command Line Interface


Sophisticated Command Line Interface provided by Nu-Coder PHP Encoder makes encoding of PHP files as easy as it gets and as configurable as possible at the same time.

7.1

How to encode PHP files using Nu-Coder Command Line Interface Nu-Coder can be invoked with various options entered on the Command Line. This section presents the syntax and required arguments for using Nu-Coder administration commands. The commands are case-sensitive.

Syntax
nu-coder.exe nu-coder.exe nu-coder.exe nu-coder.exe nu-coder.exe [options] [options] [options] [options] [options] directory targetdir [-f] file targetfile --appendext ext fileordirectory --overwrite fileordirectory

7.2

How to encode single PHP file You can run Nu-Coder in single file processing mode by specifying the source file and target file at the end of the command line:

nu-coder.exe [options] f source-file target-file When started with this command Nu-Coder will encode the source-file and save results into target-file.
Please note that some options are available in both directory and single file processing modes. For example, option --appendext <ext> is used to append <ext> at the end of source file name. This option can be used in both single file and directory processing mode and will cause Nu-Coder to append <ext> to a single files name or to all files in the source directory respectively.

7.3

How to encode PHP files in the entire directory You can run Nu-Coder in directory processing mode by specifying the source directory and target directory at the end of the command line:

nu-coder.exe [options] source-directory target-directory


When started with this command Nu-Coder will encode the files in source-

directory and save results into target-directory.


As we mentioned before some Nu-Coder CLI options are available in both directory and single file processing modes. However there is a set of options available only in directory processing mode.

- 10 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

Below are the options available only for directory processing:


-r, --recursive Handle directories recursively In directory processing mode, only encode files with the extensions listed in <extlist>. Extensions should be separated with a comma, the default <extlist> is php,inc In directory processing mode, copy all non-php files into target-directory if option --copyall is specified, Nu-Coder will encode all php files and copy all other files, except for those that match wildcard(s)specified with excludecopy option do not encode files that match specified wildcard(s). For example it will not encode config_mysite.php if --exclude option is specified as --exclude config*.php

--ext <extlist>

--copyall --excludecopy <directories and/or file extensions>

--exclude <files>

All other options are available in both directory and single file processing modes. 7.4 How to control the process of encoding of PHP files Nu-Coder interface provides various options to control what the program does and how it does it. Below is the table of Administration options of Nu-Coder Command Line Interface:
Specify the version of PHP scripts to be encoded. If omitted, the encoding will be done for PHP 5.1 Perform syntax check only, do not produce any encoded content Do not stop on errors Turn off support for short php tags <? ?> Turn on support for asp style php tags <% %> Keep extended information for debugger/ profiler. This option also automatically turns on -lineinfo option, which preserves line numbers information Preserves line numbers information Do not strip php-doc comments, useful for reflection Display this help Suppress all normal output Version number apply obfuscation supported level 1 variables will be Use custom header before encoding. Currently means that name of all local replaced with generated ones from file <fname> instead of built-in one

-c <PHP version> -s, --syntax-check -n, --noerrors -t, --noshorttags -a, --asptags

-e

--lineinfo --phpdoc -h, --help -q, --quiet -v, --version -b <level>, --obfuscation <level> -d, --header <fname>

- 11 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

--nodl --noheader

Do not use the default auto-loading header Do not add any headers

7.5

How to use License Manager generated licenses when encoding PHP files Nu-Coders License Manager allows you to generate license files, which will be required for your PHP application to run. Below is the table of options available to encode PHP files with license files generated by Nu-Coder License manager. The list of the options available for License Manager is described in later sections of this manual.
Protect encoded files with license generated with <keyword>. Generated encoded files will require appropriate license file to be loaded either in php configuration or at runtime. The license should be generated with the same keyword. Licenses generated with another keywords will be ignored Exclude specified files from any licensing protection Tells PhpExpress to automatically load the license <filename> for the file(s) encoded with this option. Otherwise license should be loaded with the call to pelm_load_license()or by using

-k <keyword>, --key <keyword>

--excludelic <files>

--licfile <filename>

phpexpress.add_license=license1.txt instruction in php.ini file


--eh <filename> Errors will be handled in the specified file, pe_error_handler() function

Please note that if --licfile option is not used during encoding process and you still want to use licenses with your PHP applications, you need to call function pelm_load_license()explicitly in PHP code or use the following instruction in php.ini file:

phpexpress.add_license=license1.txt license2.txt

7.6

Examples: The following are some examples of using Nu-Coder Command Line Interface to encode PHP files :

Example #1
Encode files in the directory c:\myproject\source and all of its subdirectories recursively and place the resulting encoded files in the directory c:\myproject\source-enc, without changing the names of the files:

nu-coder.exe -r c:\myproject\source c:\myproject\source-enc

- 12 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

Example #2
Encode files with extension .phtml in the directory c:\myproject\source and all of its subdirectories recursively and place the resulting encoded files in the same directory. c:\myproject\source-enc, without changing the names of the files:

nu-coder.exe -r --ext phtml c:\myproject\source

Example #3
Encode single file c:\myproject\index.php and store the resulting encoded file in c:\myproject\index.php.enc:

nu-coder.exe -f c:\myproject\index.php c:\myproject\index.php.enc

Example #4
Encode single file c:\myproject\index.php and append .enc to the extension of the resulting file (i.e. make it c:\myproject\index.php.enc)

nu-coder.exe --appendext .enc c:\myproject\index.php

Example #5
Encode files in the directory c:\myproject\source and all of its subdirectories recursively and place the resulting encoded files in the directory c:\myproject\source-enc, without changing the names of the files. Also copy all non-php files to c:\myproject\source-enc except for those in CVS and SVN directories and the drawings (*.dwg)

nu-coder.exe r copyall excludecopy .CVS, .SVN, *.dwg c:\myproject\source c:\myproject\source-enc

Example #6
Encode single file c:\myproject\index.php and obfuscate the code in it by replacing the names of the variables with generated ones

nu-coder.exe --obfuscation 1 c:\myproject\index.php

- 13 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

Nu-Coder License Manager


Nu-Coders license manager helps you manage the distribution of PHP applications by generating license keys that can be required by encoded files to run. Using License Manager you can create trial and demo versions of PHP applications without any code changes. License Manager is typically used on the server where the encoded files are place for download by your customers. For this reason NuSphere supplies License Manager for all major platforms, including *BSD/x86 and x86_64, Linux/x86 and x86_64,Windows x86 and x64,Solaris/x86, x86_64 and Sparc. Using Nu-Coders license manager you can create various license models for both trial and commercial distributions: Trial/Evaluation License provides time expiry Usage Restricted to specific hardware- linked to hardware id Usage Restricted to specific virtual host linked to Virtual Host Name Usage Restricted to specific Network Segment linked to ip address network card or MAC address of the network card

8.1

How to generate License Manager Licenses using Nu-Coder Command Line Interface The interface to Nu-Coders License Manager provides you with multiple options to generate License files for encoded PHP scripts. The similar syntax is used for generation of the License files as it is for encoding of php files, however the name of the executable is different. See how to encode the files to use generated licenses in the section How to use License Manager generated licenses when encoding of PHP files of this manual

Syntax
nu-licgen [options]
The following are the options used by Nu-Coders License Manager
-k <keyword>, --key <keyword> generate license with provided keyword. It's recommended to use keywords of 6-16 or more alphanumeric characters. It's necessary to encode PHP files with the same keyword or license will be ignored. add custom header to the license file create attribute(s) to be stored in license file. These attributes all are encrypted with the license key. attributes can be read from the license at runtime with pelm_get_attribute() function call. make attribute's copy visible in the license

-d <fname> --header <fname> -a <name1>=<value1>,<name2>=<value2> Or --attribute <name>=<value>,

-x <name> --expose <name>

- 14 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

--lid <id>

--lmac <mac>

lock the license into server hardware identified by specified host ID(s).(See PhpExpress API on how to get host IDs). If multiple IDs are specified, license will require at least one ID to match server hardware lock license into server hardware identified by specified Ethernet MAC addrress(es). For example --lmac 00-C0-44-11-33-A4,00-C0-44-1133-A5 lock the license into server software settings. License will work only for servers accessed with specified IP address(es). Wildcards are acceptable, for example --lip 217.217.217.5,217.217.216.* lock the license into server software settings. License will work only for accessed with specified host name(s). Wildcards are acceptable, for example --lvhost *.mydomain.com,mydomain.com

--lip <ip>

--lvhost <vhost>

--ldate <mm/dd/yyyy>

set license expiration date. Generated license will stop working after it is expired and PHP script will stop running. Useful for creation of demo versions and trials. The date must be set in the future alternative way of specifying license expiration date. Specified period should be at least one day long

--lperiod <days>

8.2

How to load license

PHP scripts protected by the license will only run if the corresponding valid license file is loaded. You can load the License in one of the following ways: Load license in php.ini file using the instruction: phpexpress.add_license = license1.txt, license2.txt This instruction is applicable to each virtual host, therefore different virtual hosts can use different licenses. Load license in .htdocs file using the instruction (will only work with php module of Apache): php_value phpexpress.add_license "license3.txt" In a file not protected by the license call the function pelm_load_license("license4.txt"). While the file containing this call can not be license protected it can still be encoded. pelm_load_license() function is a part of PhpExpress API

- 15 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

Specify the name of the license file at the time of the encoding. For example:

nu-coder -k longkeyword --licfile lic5.txt file1.php ../encoded/file1.php


Please note that if the relative path to the file is used, the system will search for the file in all directories listed in include_path 8.3 How to handle expired or invalid license If the license used for encryption of PHP files is not found or has expired or became invalid in any way, the loader (PhpExpress) will attempt to call the function pe_handle_error($errcode, $errmessage, $licfilename). To handle the error of invalid license you should implement this function in a file not protected with the license, so it could be executed in this case and provide suitable information to the user (e.g. Your Trial has expired). For example, you can encode error handler with the following parameters: --eh ./errorhandler.php NOTE: For these and other API functions used to work with License Manager please see the section How to use API provided by NuSphere PhpExpress to work with Nu-Coder of this manual. 8.4 Examples: The following are some examples of using Nu-Coder Command Line Interface to generate licenses for encoded PHP files with Nu-Coders License Manager:

Example #1
Generate license for an evaluator of the PHP application:

nu-licgen -k "super-store 1.1 trial" -a caption="super-store version 1.1" x caption --lperiod 14 license_name.txt
Generated license file license_name.txt will be good for 14 days from the moment of creation and will have one attribute called caption. Attribute caption is going to be visible in the license file. To protect PHP files in c:\myproject\source with license_name.txt (generated with the command shown above) the following syntax should be used for encoding:

nu-coder.exe -k "super-store 1.1 trial" c:\myproject\source

Example #2
Generate the license for commercial PHP application and link it to host id HVCE42C61936X (host id should be obtained from the client. PhpExpress provides API function phpexpress_hostid() that can be used for this purpose, described later in the this manual)

- 16 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

nu-licgen -k "1.1 super-store commercial" -a caption=" super-store version 1.1",licensee="John Doe" -x caption,licensee --lid HVCE42C-61936X license_name.txt
In this example, the license file generate will allow the execution of PHP files only on the host id HVCE42C-61936X. To link PHP files from c:\myproject\source to license_name.txt the following syntax should be used for encoding (same as in the Example #1 of this section):

nu-coder.exe -k "super-store 1.1 trial" c:\myproject\source

- 17 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

9
9.1

Deploying Encoded PHP files with NuSphere PhpExpress


Overview of NuSphere PhpExpress PHP files encoded with NuSphere Nu-Coder require special loader present in PHP interpreter. PhpExpress is NuSphere Free PHP loader and accelerator that provides support for encoded files and also speeds up the execution of regular PHP files. PhpExress extensions for all operating systems can be found in the folder "loader" of your Nu-Coder installation. PhpExpress can be downloaded from NuSphere website and distributed Free Of Charge without limitations in unmodified form. Every Nu-Coder installation also comes with PhpExpress. This is how PhpExpress works: When PHP interpreter executes any PHP script it first compiles the script into bytecodes. However Nu-Coder produces PHP files that have been already compiled into bytecodes. PhpExpress loads encoded PHP scripts directly into PHP engine saving time and boosting performance of PHP interpretor PhpExpress checks for license file if required either via API call in the script to pelm_is_licensed() function (described later in this manual) or licfile encoding option PhpExpress also implements caching for PHP engine and accelerates execution process even if PHP Script is not encoded

9.2

How to deploy NuSphere PhpExpress NuSphere PhpExpress is a regular PHP extension, which makes it easy to install and deploy. To install PhpExpress: Open php.ini file for editing Add line zend_extension_ts=c:\full\path\to\phpexpress-php-x.x.dll if you are deploying on Windows, or zend_extension=/full/path/to/phpexpress-php-x.x.so if you are deploying on Unix, Linux or Mac OS operating systems Copy phpexpress-php-x.x.dll or phpexpress-php-x.x.so in the PHP extensions directory specified in php.ini file Stop and Start Apache if you are running PHP as Apache module Execute call to phpinfo() function and make sure that PhpExpress is properly installed Once PhpExpress is installed on the server, you can execute PHP Scripts encoded with Nu-Coder as well as regular, not encoded PHP scripts. In both cases you will gain an improved performance in the execution of the scripts.

9.3

How to use API provided by NuSphere PhpExpress to work with Nu-Coder PhpExpress provides a number of PHP Functions useful when encoding PHP files with and without Nu-Coders License Manager. The following functions are likely to be used by the users deploying files encoded with PHP Enoder:

- 18 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

void phpexpress() shows phpexpress info page. array phpexpress_hostid(); returns the list of host IDs that identify server hardware. Note: all host IDs are shown on the PhpExpress info page. It's recommended to use ALL host IDs that are found on the system. It will make license less sensitive to the hardware changes. The following functions are likely to be used by PHP developers deploying their PHP applications encoded by Nu-Coder: bool pelm_is_licensed(); returns true if caller script is protected with license bool pelm_load_license(string filename); loads license and returns true if file is found. NOTE: if relative path name is specified, PhpExpress will use include_path php setting to find the file. For further details about include_path see php manual. string pelm_license_filename() returns license filename that is applied to the caller script. It returns false if no license is used. string pelm_get_attribute(string attr_name); reads attribute value from the license applied to the caller script. It returns false if no license is used. pe_handle_error($errcode, $errmessage, $licfilename) gets called if the license is not found, expired or not valid for any other reason. Possible error codes are: PE_ERR_NO_LIC no licenses found PE_ERR_NO_VALID_LIC the license is found but it is not applicable for this application PE_ERR_EXPIRED_LIC license is expired PE_ERR_HOST_MISMATCH_LIC license doesnt match the host (by IP or HTTP host) PE_ERR_HW_MISMATCH_LIC license is generated for a different hostid

9.4

How to monitor PHP Cache implemented by NuSphere PhpExpress PhpExpress accelerates execution of PHP scripts by caching them and avoiding unnecessary compilation. You can view and control PHP Cache created by PhpExpress with a single function call to the PHP function phpexpress() provided by PhpExpress PHP extension. phpexpress() produces the output similar to phpinfo() with the user Interface to administer PhpExpress cache. The output of phpexpress() is illustrated below:

- 19 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

Please note that PHP caching is only enabled when PHP is running as an extension of the Web Server dll on windows or shared object on Linux/Unix/Mac Operating Systems. Caching of PHP scripts when PHP is running in CGI mode is not useful and therefore disabled.

- 20 -

Nu-Coder Encoder Version 2.0 User Guide. Copyright 2002-2008 NuSphere Corporation.

10 Deploying Encoded PHP files with NuSphere PhpDock


NuSphere PhpDock is a unique PHP deployment solution, which enables you to deploy any PHP web application as a Stand Alone Windows Desktop application w/o any changes in the code. Starting with version 1.6 PhpDock fully supports deployment of encoded PHP files same way it does it with regular PHP and HTML source files. No additional action is required.

- 21 -

You might also like