Skip to content

How Compiled PHP Console Applications (CLI) Work

ExeOutput for PHP can create console applications without a GUI. These applications operate as if PHP were executed in CLI mode.

Console APP

You can decide whether to create a GUI or a console application when starting a new project. This choice is final! The status bar of ExeOutput for PHP indicates whether you are working on a GUI or a console application:

Console APP in status bar

ExeOutput for PHP creates a single, stand-alone executable file: end users simply launch the resulting EXE file. No PHP installation is necessary. All compiled files are automatically loaded into the PHP runtime upon request.

By default, the index page script runs at startup. You can specify a different command line in the PHP Settings => Main Settings page.

Warning

Console applications cannot prompt for elevated rights: use an administrator command prompt to perform administrative tasks.

The function exo_get_resstring can be used to protect resource strings.

Warning

Many ExeOutput for PHP features are NOT supported by console applications: global variables, global protection (security), HEScript scripting...

Access the Folder Containing the .EXE File

Do not use $_SERVER['DOCUMENT_ROOT'] because the $_SERVER variable is empty in a console application (not running on a server and it is not processing an HTTP request).

To get the full path to the EXE directory, use this code: dirname(__DIR__)

For example: print(dirname(__DIR__));

Script Example

The following code was used to generate the console app screenshot shown above.

<?php

print("Hello World from a console app made with ExeOutput for PHP!\n");

print(exo_get_protstring('str1'));

fputs(STDOUT, "\nThe Amazing Favourite Colour Script\n");
fputs(STDOUT, "What is your favourite colour? ");

$sometext = strtolower(trim(fgets(STDIN, 256)));
fputs(STDOUT, "Your favourite colour is $sometext!\n\n");
?>