PHP can run in different environments. The most common environment is CGI, which runs when PHP processes an HTTP request. However, it is also possible to run a PHP script from the Terminal, in which case it is a so-called CLI (Command-line interface) task.
CGI SAPI, CLI does not write any headers to the output by default.php.ini directives that are overridden in CLI SAPI because they are meaningless in a shell environment:html_errors: CLI defaults to FALSE.implicit_flush: default CLI value is TRUEmax_execution_time: default CLI value is 0 (unlimited)register_argc_argv: default CLI value is TRUE$argc variable gives you the number of arguments passed to the application. And the $argv field gives you an array of actual argumentsSTDIN, STDOUT, STDERR. All are file handlers for the corresponding shell device. For example, STDIN is a file handler for fopen('php://stdin', 'r'). So you can read a line from STDIN like this: $strLine = trim(fgets(STDIN));. The STDIN is already defined for you using the PHP CLI.php-cgi.exe (formerly php.exe) and the CLI version is now located in the main directory (formerly cli/php.exe).php-win.exe. This is equivalent to the CLI version, except that in php-win nothing is printed, and thus provides no console (no "dos box" is displayed on the screen). This behaviour is similar to PHP GTK.Jan Barášek Více o autorovi
Autor článku pracuje jako seniorní vývojář a software architekt v Praze. Navrhuje a spravuje velké webové aplikace, které znáte a používáte. Od roku 2009 nabral bohaté zkušenosti, které tímto webem předává dál.
Rád vám pomůžu:
Články a novinky nejen ze světa PHP a programování. Nenechte si ujít jediný článek.
Články píše Jan Barášek © 2009-2025 | Kontakt | Mapa webu
Status | Aktualizováno: ... | en