How Compiled PHP Console Applications (CLI) Work

ExeOutput for PHP can create console applications with no GUI. These applications work as if PHP was run in CLI mode.

Console APP

You can choose whether you want to create a GUI or console application when you start a new project. This choice is definitive! The status bar of ExeOutput for PHP tells you whether you are working with a GUI or console application:

Console APP in status bar

ExeOutput for PHP creates a single and stand-alone executable file: end users just launch the resulting EXE file. No PHP installation is required. All compiled files are automatically fed into the PHP runtime when requested.

By default, the index page script is executed at startup. You can define another command line in the PHP Settings => Main Setting page.

A console application cannot prompt for elevated rights: use an administrator command prompt to complete administrative tasks.

exo_get_resstring can be used to protect resource strings.

A lof of ExeOutput for PHP features are NOT handled by console applications: global variables, global protection (security), HEScript scripting…

Access the folder that contains 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 dir, use this code: dirname(__DIR__)

For instance: print (dirname(__DIR__));

Script Example

The following code was used to render the console app whose screenshot is available 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");

?>


Copyright G.D.G. Software 2018. All Rights Reserved.