features/commandline.xml
8cb32bd2c0f0b8a95ebb84b211920fe10d4c2679
...
...
@@ -5,7 +5,7 @@
5
5
<titleabbrev>Command line usage</titleabbrev>
6
6
7
7
<!--Introduction: {{{-->
8
-
<section xml:id="features.commandline.introduction">
8
+
<section xml:id="features.commandline.introduction" annotations="chunk:false">
9
9
<title>Introduction</title>
10
10
11
11
<para>
...
...
@@ -56,7 +56,7 @@
56
56
</note>
57
57
58
58
<para>
59
-
As of PHP 5, the &cli; binary is distributed in the main folder as <filename>
59
+
The &cli; binary is distributed in the main folder as <filename>
60
60
php.exe</filename> on Windows. The <acronym>CGI</acronym> version is
61
61
distributed as <filename>php-cgi.exe</filename>. Additionally, a <filename>
62
62
php-win.exe</filename> is distributed if PHP is configured using
...
...
@@ -139,7 +139,7 @@
139
139
<entry>&false;</entry>
140
140
<entry>
141
141
Defaults to &false;, as it can be quite hard to read error messages
142
-
in the shell enviroment when they are cluttered up with uninterpreted
142
+
in the shell environment when they are cluttered up with uninterpreted
143
143
<acronym>HTML</acronym> tags.
144
144
</entry>
145
145
</row>
...
...
@@ -462,6 +462,7 @@ $ php -c /custom/directory/custom-file.ini my_script.php
462
462
</screen>
463
463
</para>
464
464
<para><example>
465
+
<title>Example of using <literal>-d</literal> to set an INI setting</title>
465
466
<screen>
466
467
<![CDATA[
467
468
# Omitting the value part will set the given configuration directive to "1"
...
...
@@ -506,13 +507,6 @@ string(15) "doesntmakesense"
506
507
<option>-f</option> is optional and may be omitted - providing just
507
508
the filename to execute is sufficient.
508
509
</para>
509
-
<note>
510
-
<para>
511
-
To pass arguments to a script, the first argument must be
512
-
<literal>--</literal>, otherwise PHP will interpret them as PHP
513
-
options.
514
-
</para>
515
-
</note>
516
510
</entry>
517
511
</row>
518
512
<row>
...
...
@@ -660,7 +654,7 @@ array(370) {
660
654
experienced - if appropriate, a bug report should be opened at
661
655
<link xlink:href="&url.php.bugs;">&url.php.bugs;</link>.
662
656
It is still easy to run into trouble when trying to use variables
663
-
(shell or PHP) in commnad-line code, or using backslashes for
657
+
(shell or PHP) in command-line code, or using backslashes for
664
658
escaping, so take great care when doing so. You have been warned!
665
659
</para>
666
660
</note>
...
...
@@ -686,7 +680,7 @@ array(370) {
686
680
<entry>--process-begin</entry>
687
681
<entry>
688
682
<para>
689
-
PHP code to execute before processing stdin. Added in PHP 5.
683
+
PHP code to execute before processing stdin.
690
684
</para>
691
685
</entry>
692
686
</row>
...
...
@@ -695,7 +689,7 @@ array(370) {
695
689
<entry>--process-code</entry>
696
690
<entry>
697
691
<para>
698
-
PHP code to execute for every input line. Added in PHP 5.
692
+
PHP code to execute for every input line.
699
693
</para>
700
694
<para>
701
695
There are two special variables available in this mode:
...
...
@@ -711,7 +705,7 @@ array(370) {
711
705
<entry>--process-file</entry>
712
706
<entry>
713
707
<para>
714
-
PHP file to execute for every input line. Added in PHP 5.
708
+
PHP file to execute for every input line.
715
709
</para>
716
710
</entry>
717
711
</row>
...
...
@@ -720,7 +714,7 @@ array(370) {
720
714
<entry>--process-end</entry>
721
715
<entry>
722
716
<para>
723
-
PHP code to execute after processing the input. Added in PHP 5.
717
+
PHP code to execute after processing the input.
724
718
</para>
725
719
<para><example>
726
720
<title>Using the <option>-B</option>, <option>-R</option> and
...
...
@@ -742,7 +736,7 @@ Total Lines: 37328
742
736
<entry>
743
737
<para>
744
738
Starts <link linkend="features.commandline.webserver">built-in web
745
-
server</link>. Available as of PHP 5.4.0.
739
+
server</link>.
746
740
</para>
747
741
</entry>
748
742
</row>
...
...
@@ -752,7 +746,6 @@ Total Lines: 37328
752
746
<entry>
753
747
Specifies document root for <link
754
748
linkend="features.commandline.webserver">built-in web server</link>.
755
-
Available as of PHP 5.4.0.
756
749
</entry>
757
750
</row>
758
751
<row>
...
...
@@ -830,8 +823,7 @@ Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
830
823
<entry>--ini</entry>
831
824
<entry>
832
825
<para>
833
-
Show configuration file names and scanned directories. Available as
834
-
of PHP 5.2.3.
826
+
Show configuration file names and scanned directories.
835
827
<example>
836
828
<title><literal>--ini</literal> example</title>
837
829
<programlisting role="shell">
...
...
@@ -853,7 +845,7 @@ Additional .ini files parsed: (none)
853
845
<entry>
854
846
<para>
855
847
Show information about the given function or class method (e.g.
856
-
number and name of the parameters). Available as of PHP 5.1.2.
848
+
number and name of the parameters).
857
849
</para>
858
850
<para>
859
851
This option is only available if PHP was compiled with
...
...
@@ -884,7 +876,7 @@ Function [ <internal> public function var_dump ] {
884
876
<entry>
885
877
<para>
886
878
Show information about the given class (list of constants, properties
887
-
and methods). Available as of PHP 5.1.2.
879
+
and methods).
888
880
</para>
889
881
<para>
890
882
This option is only available if PHP was compiled with
...
...
@@ -933,7 +925,7 @@ Class [ <internal:standard> class Directory ] {
933
925
<entry>
934
926
<para>
935
927
Show information about the given extension (list of &php.ini; options,
936
-
defined functions, constants and classes). Available as of PHP 5.1.2.
928
+
defined functions, constants and classes).
937
929
</para>
938
930
<para>
939
931
This option is only available if PHP was compiled with
...
...
@@ -967,7 +959,6 @@ Extension [ <persistent> extension #19 json version 1.2.1 ] {
967
959
<para>
968
960
Show the configuration information for the given Zend extension (the
969
961
same information that is returned by <function>phpinfo</function>).
970
-
Available as of PHP 5.4.0.
971
962
</para>
972
963
</entry>
973
964
</row>
...
...
@@ -978,7 +969,7 @@ Extension [ <persistent> extension #19 json version 1.2.1 ] {
978
969
<para>
979
970
Show the configuration information for the given extension (the same
980
971
information that is returned by <function>phpinfo</function>).
981
-
Available as of PHP 5.2.2. The core configuration information
972
+
The core configuration information
982
973
is available using "main" as extension name.
983
974
</para>
984
975
<para>
...
...
@@ -1049,12 +1040,6 @@ $ php -f my_script.php
1049
1040
restriction on which files can be executed; in particular, the filename
1050
1041
is not required have a <literal>.php</literal> extension.
1051
1042
</para>
1052
-
<note>
1053
-
<para>
1054
-
If arguments need to be passed to the script when using
1055
-
<option>-f</option>, the first argument must be <literal>--</literal>.
1056
-
</para>
1057
-
</note>
1058
1043
</listitem>
1059
1044
<listitem>
1060
1045
<para>
...
...
@@ -1110,8 +1095,8 @@ $ some_application | some_filter | php | sort -u > final_output.txt
1110
1095
first index (zero) always contains the name of the script as called from the
1111
1096
command line. Note that, if the code is executed in-line using the command
1112
1097
line switch <option>-r</option>, the value of <varname>$argv[0]</varname>
1113
-
will be just a dash (<literal>-</literal>). The same is true if the code is
1114
-
executed via a pipe from <literal>STDIN</literal>.
1098
+
will be <literal>"Standard input code"</literal>; prior to PHP 7.2.0, it was a dash (<literal>"-"</literal>) instead. The same is true if the code is
1099
+
executed via a pipe from <constant>STDIN</constant>.
1115
1100
</para>
1116
1101

1117
1102
<para>
...
...
@@ -1267,7 +1252,7 @@ This is a command line PHP script with one option.
1267
1252
<para>
1268
1253
<example>
1269
1254
<title>Batch file to run a command line PHP script (script.bat)</title>
1270
-
<programlisting role="shell">
1255
+
<programlisting role="winbat">
1271
1256
<![CDATA[
1272
1257
@echo OFF
1273
1258
"C:\php\php.exe" script.php %*
...
...
@@ -1295,6 +1280,14 @@ This is a command line PHP script with one option.
1295
1280
extension, as described in <link linkend="install.windows.commandline">Command
1296
1281
Line PHP on Microsoft Windows</link>.
1297
1282
</para>
1283
+

1284
+
<note>
1285
+
<para>
1286
+
On Windows it is recommended to run PHP under an actual user account.
1287
+
When running under a network service certain operations will fail, because
1288
+
"No mapping between account names and security IDs was done".
1289
+
</para>
1290
+
</note>
1298
1291
</section>
1299
1292
<!--}}}-->
1300
1293
...
...
@@ -1405,9 +1398,11 @@ php -r 'fwrite(STDERR, "stderr\n");'
1405
1398
<title>Interactive shell</title>
1406
1399

1407
1400
<para>
1408
-
As of PHP 5.1.0, the &cli.sapi; provides an interactive shell using the
1401
+
The &cli.sapi; provides an interactive shell using the
1409
1402
<option>-a</option> option if PHP is compiled with the <option
1410
1403
role="configure">--with-readline</option> option.
1404
+
As of PHP 7.1.0 the interactive shell is also available on Windows, if the
1405
+
<link linkend="book.readline">readline extension</link> is enabled.
1411
1406
</para>
1412
1407

1413
1408
<para>
...
...
@@ -1482,7 +1477,7 @@ php > $foo[TAB]ThisIsAReallyLongVariableName
1482
1477
</para>
1483
1478

1484
1479
<para>
1485
-
As of PHP 5.4.0, the &cli.sapi; provides
1480
+
The &cli.sapi; provides
1486
1481
the &php.ini; settings <parameter>cli.pager</parameter> and
1487
1482
<parameter>cli.prompt</parameter>. The <parameter>cli.pager</parameter>
1488
1483
setting allows an external program (such as <filename>less</filename>) to
...
...
@@ -1492,7 +1487,7 @@ php > $foo[TAB]ThisIsAReallyLongVariableName
1492
1487
</para>
1493
1488

1494
1489
<para>
1495
-
In PHP 5.4.0 it was also made possible to set
1490
+
It is also possible to set
1496
1491
&php.ini; settings in the interactive shell using a shorthand notation.
1497
1492
</para>
1498
1493

...
...
@@ -1588,12 +1583,22 @@ php >
1588
1583
</para>
1589
1584
</note>
1590
1585

1591
-
<note>
1586
+
<section xml:id="features.commandline.interactive.mode">
1587
+
<title>Interactive mode</title>
1592
1588
<para>
1593
-
<link linkend="language.oop5.autoload">Autoloading</link> is not
1594
-
available if using PHP in &cli; interactive mode.
1589
+
If the readline extension is not available, prior to PHP 8.1.0, invoking the &cli.sapi; with the
1590
+
<option>-a</option> option provided the interactive mode. In this mode, a
1591
+
complete PHP script is supposed to be given via STDIN, and after termination
1592
+
with <literal>CRTL+d</literal> (POSIX) or <literal>CTRL+z</literal>
1593
+
followed by <literal>ENTER</literal> (Windows), this script is evaluated.
1594
+
This is basically the same as invoking the &cli.sapi; without the <option>-a</option>
1595
+
option.
1595
1596
</para>
1596
-
</note>
1597
+
<para>
1598
+
As of PHP 8.1.0, invoking the &cli.sapi; with the <option>-a</option> option
1599
+
fails, if the readline extension is not available.
1600
+
</para>
1601
+
</section>
1597
1602
</section>
1598
1603
<!--}}}-->
1599
1604

...
...
@@ -1603,7 +1608,7 @@ php >
1603
1608

1604
1609
<warning>
1605
1610
<para>
1606
-
This web server was designed to aid application development. It may also
1611
+
This web server is designed to aid application development. It may also
1607
1612
be useful for testing purposes or for application demonstrations that are
1608
1613
run in controlled environments. It is not intended to be a full-featured
1609
1614
web server. It should not be used on a public network.
...
...
@@ -1611,11 +1616,12 @@ php >
1611
1616
</warning>
1612
1617

1613
1618
<para>
1614
-
As of PHP 5.4.0, the &cli.sapi; provides a built-in web server.
1619
+
The &cli.sapi; provides a built-in web server.
1615
1620
</para>
1616
1621

1617
1622
<para>
1618
-
PHP applications will stall if a request is blocked.
1623
+
The web server runs only one single-threaded process, so
1624
+
PHP applications will stall if a request is blocked.
1619
1625
</para>
1620
1626

1621
1627
<para>
...
...
@@ -1623,8 +1629,11 @@ php >
1623
1629
PHP was started, unless the -t option is used to specify an
1624
1630
explicit document root. If a URI request does not specify a file,
1625
1631
then either index.php or index.html in the given directory are
1626
-
returned. If neither file exists, then a 404 response code is
1627
-
returned.
1632
+
returned. If neither file exists, the lookup for index.php and index.html
1633
+
will be continued in the parent directory and so on until one is found or
1634
+
the document root has been reached. If an index.php or index.html is found,
1635
+
it is returned and $_SERVER['PATH_INFO'] is set to the trailing part of
1636
+
the URI. Otherwise a 404 response code is returned.
1628
1637
</para>
1629
1638

1630
1639
<para>
...
...
@@ -1636,61 +1645,82 @@ php >
1636
1645
</para>
1637
1646

1638
1647
<para>
1639
-
Standard MIME types are returned for files with extensions: .3gp,
1640
-
.apk, .avi, .bmp, .css, .csv, .doc, .docx, .flac, .gif, .gz,
1641
-
.gzip, .htm, .html, .ics, .jpe, .jpeg, .jpg, .js, .kml, .kmz,
1642
-
.m4a, .mov, .mp3, .mp4, .mpeg, .mpg, .odp, .ods, .odt, .oga, .ogg,
1643
-
.ogv, .pdf, .pdf, .png, .pps, .pptx, .qt, .svg, .swf, .tar, .text,
1644
-
.tif, .txt, .wav, .webm, .wmv, .xls, .xlsx, .xml, .xsl, .xsd, and .zip.
1648
+
Standard MIME types are returned for files with extensions:
1649
+
<simplelist type="inline">
1650
+
<member><literal>.3gp</literal></member>
1651
+
<member><literal>.apk</literal></member>
1652
+
<member><literal>.avi</literal></member>
1653
+
<member><literal>.bmp</literal></member>
1654
+
<member><literal>.css</literal></member>
1655
+
<member><literal>.csv</literal></member>
1656
+
<member><literal>.doc</literal></member>
1657
+
<member><literal>.docx</literal></member>
1658
+
<member><literal>.flac</literal></member>
1659
+
<member><literal>.gif</literal></member>
1660
+
<member><literal>.gz</literal></member>
1661
+
<member><literal>.gzip</literal></member>
1662
+
<member><literal>.htm</literal></member>
1663
+
<member><literal>.html</literal></member>
1664
+
<member><literal>.ics</literal></member>
1665
+
<member><literal>.jpe</literal></member>
1666
+
<member><literal>.jpeg</literal></member>
1667
+
<member><literal>.jpg</literal></member>
1668
+
<member><literal>.js</literal></member>
1669
+
<member><literal>.kml</literal></member>
1670
+
<member><literal>.kmz</literal></member>
1671
+
<member><literal>.m4a</literal></member>
1672
+
<member><literal>.mov</literal></member>
1673
+
<member><literal>.mp3</literal></member>
1674
+
<member><literal>.mp4</literal></member>
1675
+
<member><literal>.mpeg</literal></member>
1676
+
<member><literal>.mpg</literal></member>
1677
+
<member><literal>.odp</literal></member>
1678
+
<member><literal>.ods</literal></member>
1679
+
<member><literal>.odt</literal></member>
1680
+
<member><literal>.oga</literal></member>
1681
+
<member><literal>.ogg</literal></member>
1682
+
<member><literal>.ogv</literal></member>
1683
+
<member><literal>.pdf</literal></member>
1684
+
<member><literal>.png</literal></member>
1685
+
<member><literal>.pps</literal></member>
1686
+
<member><literal>.pptx</literal></member>
1687
+
<member><literal>.qt</literal></member>
1688
+
<member><literal>.svg</literal></member>
1689
+
<member><literal>.swf</literal></member>
1690
+
<member><literal>.tar</literal></member>
1691
+
<member><literal>.text</literal></member>
1692
+
<member><literal>.tif</literal></member>
1693
+
<member><literal>.txt</literal></member>
1694
+
<member><literal>.wav</literal></member>
1695
+
<member><literal>.webm</literal></member>
1696
+
<member><literal>.wmv</literal></member>
1697
+
<member><literal>.xls</literal></member>
1698
+
<member><literal>.xlsx</literal></member>
1699
+
<member><literal>.xml</literal></member>
1700
+
<member><literal>.xsl</literal></member>
1701
+
<member><literal>.xsd</literal></member>
1702
+
<member><literal>.zip</literal></member>
1703
+
</simplelist>
1704
+
.
1645
1705
</para>
1646
1706

1647
-

1648
-
<table>
1649
-
<title>Changelog: Supported MIME Types (file extensions)</title>
1650
-
<tgroup cols="2">
1651
-
<thead>
1652
-
<row>
1653
-
<entry>&Version;</entry>
1654
-
<entry>&Description;</entry>
1655
-
</row>
1656
-
</thead>
1657
-
<tbody>
1658
-
<row>
1659
-
<entry>5.5.12</entry>
1660
-
<entry>
1661
-
.xml, .xsl, and .xsd
1662
-
</entry>
1663
-
</row>
1664
-
<row>
1665
-
<entry>5.5.7</entry>
1666
-
<entry>
1667
-
.3gp, .apk, .avi, .bmp, .csv, .doc, .docx, .flac, .gz, .gzip,
1668
-
.ics, .kml, .kmz, .m4a, .mp3, .mp4, .mpg, .mpeg, .mov, .odp, .ods,
1669
-
.odt, .oga, .pdf, .pptx, .pps, .qt, .swf, .tar, .text, .tif, .wav,
1670
-
.wmv, .xls, .xlsx, and .zip
1671
-
</entry>
1672
-
</row>
1673
-
<row>
1674
-
<entry>5.5.5</entry>
1675
-
<entry>
1676
-
.pdf
1677
-
</entry>
1678
-
</row>
1679
-
<row>
1680
-
<entry>5.4.11</entry>
1681
-
<entry>
1682
-
.ogg, .ogv, and .webm
1683
-
</entry>
1684
-
</row>
1685
-
<row>
1686
-
<entry>5.4.4</entry>
1687
-
<entry>
1688
-
.htm and .svg
1689
-
</entry>
1690
-
</row>
1691
-
</tbody>
1692
-
</tgroup>
1693
-
</table>
1707
+
<simpara>
1708
+
As of PHP 7.4.0, the built-in webserver can be configured to fork multiple
1709
+
workers in order to test code that requires multiple concurrent requests
1710
+
to the built-in webserver.
1711
+
Set the <envar>PHP_CLI_SERVER_WORKERS</envar> environment variable to the
1712
+
number of desired workers before starting the server.
1713
+
</simpara>
1714
+
<note>
1715
+
<simpara>This feature is not supported on Windows.</simpara>
1716
+
</note>
1717
+
<warning>
1718
+
<para>
1719
+
This <emphasis>experimental</emphasis> feature is <emphasis>not</emphasis>
1720
+
intended for production usage. Generally, the built-in Web Server is
1721
+
<emphasis>not</emphasis> intended for production usage.
1722
+
</para>
1723
+
</warning>
1694
1724

1695
1725
<example>
1696
1726
<title>Starting the web server</title>
...
...
@@ -1729,6 +1759,10 @@ Press Ctrl-C to quit.
1729
1759
[Thu Jul 21 10:48:52 2011] ::1:39149 GET /favicon.ico - Request read
1730
1760
]]>
1731
1761
</screen>
1762
+
<para>
1763
+
Note that prior to PHP 7.4.0, symlinked statical resources have not been
1764
+
accessible on Windows, unless the router script would handle these.
1765
+
</para>
1732
1766
</example>
1733
1767

1734
1768
<example>
...
...
@@ -1825,14 +1859,19 @@ $ php -S localhost:8000 router.php
1825
1859

1826
1860
<example>
1827
1861
<title>Accessing the CLI Web Server From Remote Machines</title>
1828
-
<para>
1829
-
You can make the web server accessible on port 8000 to any interface with:
1830
-
</para>
1862
+
<para>
1863
+
You can make the web server accessible on port 8000 to any interface with:
1864
+
</para>
1831
1865
<programlisting role="shell">
1832
1866
<![CDATA[
1833
1867
$ php -S 0.0.0.0:8000
1834
1868
]]>
1835
1869
</programlisting>
1870
+
<warning>
1871
+
<para>
1872
+
The built-in Web Server should not be used on a public network.
1873
+
</para>
1874
+
</warning>
1836
1875
</example>
1837
1876

1838
1877
</section>
...
...
@@ -1852,12 +1891,12 @@ $ php -S 0.0.0.0:8000
1852
1891
<entry>&Changelog;</entry>
1853
1892
</row>
1854
1893
</thead>
1855
-
<tbody>
1894
+
<tbody xml:id="features.commandline.ini.list">
1856
1895
<row>
1857
1896
<entry><link linkend="ini.cli-server.color">cli_server.color</link></entry>
1858
1897
<entry>"0"</entry>
1859
-
<entry>PHP_INI_ALL</entry>
1860
-
<entry>Available since PHP 5.4.0.</entry>
1898
+
<entry><constant>INI_ALL</constant></entry>
1899
+
<entry></entry>
1861
1900
</row>
1862
1901
</tbody>
1863
1902
</tgroup>
...
...
@@ -1871,7 +1910,7 @@ $ php -S 0.0.0.0:8000
1871
1910
<varlistentry xml:id="ini.cli-server.color">
1872
1911
<term>
1873
1912
<parameter>cli_server.color</parameter>
1874
-
<type>boolean</type>
1913
+
<type>bool</type>
1875
1914
</term>
1876
1915
<listitem>
1877
1916
<para>
1878
1917