print Bundled CLI Tools

Scorpio is shipped with several CLI utilities. These are located in the /tools folder and can be executed via the PHP CLI binary. They are not essential, but can help with development.

To make the most of the CLI tools you will need the POSIX and PCNTL extensions for PHP. These are not available for Windows systems, so to help run cross-platform patch files are included that will implement the functions to prevent undefined or unknown function errors. On Fedora systems POSIX controls are usually named as php-process in yum and similarly in Debian distributions. You can compile the extensions yourself as needed.

Please note: a CGI binary is NOT the same as a CLI PHP binary. These tools should not be run under a CGI or web process.

There are two classes of CLI tools in Scorpio:


The first type is an application. This is a command line script that uses the cliApplication classes and allows small to large command line tools to be created. Typically these tools run once, execute quickly and when they have completed their task, finish and exit.

All cliApplications bundled with Scorpio share several components:

The following applications are available within the /tools folder:

cliUtils and processLog are more examples of what can be done. cliUtils allows a string to be hashed using passwordHash or to serialise a string via PHPs serialise. They are more for convenience when updating database records manually.

processLog will output process information to a log file via the ps command. This will only function on Linux / Unix systems. This is for tracking memory usage over long running scripts.


The second type is a daemon application. This is a long running process that usually runs as a different user (requires root or sudo access), that will handle the processing of a queue or batches. Daemons run in the background and are used all the time for server processes: web servers, database servers etc.

cliDaemons require the PCNTL library but can be run in a no-daemon form using --nodaemon.

Scorpio comes with an example logging daemon. This will read the logQueue entries and write them to the appropriate file specified in the log entry. The system is based around MySQL but can be easily ported to another architecture. Database logging is useful in distributed systems were several machines will run the same task but you want unified logging on a single machine.

While PHP may not be the first choice for these types of processes, with careful writing it is possible to make fairly efficient and useful systems. If high performance is required, then obviously another language should be used, however the benefit of a PHP daemon is that your PHP objects and data layer can be re-used without additional work.

<  1  >