- Some structuring

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@132304 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Derick Rethans 2003-06-18 10:38:43 +00:00
parent 57a2286bcc
commit c83f0d38ac
2 changed files with 69 additions and 55 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.22 $ -->
<!-- $Revision: 1.23 $ -->
<chapter id="features.commandline">
<title>Using PHP from the command line</title>
<!-- NEW DOCUMENTATION STARTS -->
@ -43,37 +43,43 @@
install</literal>. Alternatively you can specify <literal>--disable-cgi
</literal> in your configure line.
</para>
<note>
<para>
Because both <literal>--enable-cli</literal> and <literal>
--enable-cgi</literal> are enabled by default, simply having
<literal>--enable-cli</literal> in your configure line does
not necessarily mean the CLI will be copied as <literal>
{PREFIX}/bin/php</literal> during <literal>make install</literal>.
</para>
</note>
<para>
<note>
<para>
Because both <literal>--enable-cli</literal> and <literal>
--enable-cgi</literal> are enabled by default, simply having
<literal>--enable-cli</literal> in your configure line does
not necessarily mean the CLI will be copied as <literal>
{PREFIX}/bin/php</literal> during <literal>make install</literal>.
</para>
</note>
</para>
<para>
The windows packages between PHP 4.2.0 and PHP 4.2.3 distributed the CLI as
<filename>php-cli.exe</filename>,living in the same folder as the CGI
<filename>php-cli.exe</filename>, living in the same folder as the CGI
<filename>php.exe</filename>. Starting with PHP 4.3.0 the windows package
distributes the CLI as <filename>php.exe</filename> in a separate folder named cli,
so <literal>cli/php.exe</literal>.
distributes the CLI as <filename>php.exe</filename> in a separate folder
named <literal>cli</literal>, so <literal>cli/php.exe</literal>.
</para>
<para>
<note>
<title>What SAPI do I have?</title>
<para>
From a shell, typing <literal>php -v</literal> will tell you
whether <literal>php</literal> is CGI or CLI. See also the function
<function>php_sapi_name</function> and the constant <constant>
PHP_SAPI</constant>.
</para>
</note>
</para>
<para>
<note>
<para>
A unix <literal>man</literal>ual page was added in PHP 4.3.2. You may
view this by typing <literal>man php</literal> in your shell environment.
</para>
</note>
</para>
<note>
<title>What SAPI do I have?</title>
<para>
From a shell, typing <literal>php -v</literal> will tell you
whether <literal>php</literal> is CGI or CLI. See also the function
<function>php_sapi_name</function> and the constant <constant>
PHP_SAPI</constant>.
</para>
</note>
<note>
<para>
A unix <literal>man</literal>ual page was added in PHP 4.3.2. You may
view this by typing <literal>man php</literal> in your shell environment.
</para>
</note>
<para>
Remarkable differences of the <literal>CLI SAPI</literal> compared to other
<literal>SAPI</literal>s:
@ -104,6 +110,8 @@
<para>
There are certain &php.ini; directives which are overriden by the <literal>CLI
SAPI</literal> because they do not make sense in shell environments:
</para>
<para>
<table>
<title>Overriden &php.ini; directives</title>
<tgroup cols="3">
@ -427,7 +435,8 @@ $ some_application | some_filter | php | sort -u >final_output.txt
<literal>PHP</literal>, every argument following it is passed
untouched to your script.
</para>
<screen>
<para>
<screen>
<![CDATA[
# This will not execute the given code but will show the PHP usage
$ php -r 'var_dump($argv);' -h
@ -443,7 +452,8 @@ array(2) {
string(2) "-h"
}
]]>
</screen>
</screen>
</para>
<para>
However, there's another way of using <literal>PHP</literal> for shell
scripting. You can write a script where the first line starts with
@ -973,9 +983,10 @@ Usage: php [-q] [-h] [-s [-v] [-i] [-f <file>] | {<file> [args...]}
hurt on Windows, so you can write cross platform programs this way. A simple
example of writing a command line PHP program can be found below.
</para>
<example>
<title>Script intended to be run from command line (script.php)</title>
<programlisting role="php">
<para>
<example>
<title>Script intended to be run from command line (script.php)</title>
<programlisting role="php">
<![CDATA[
#!/usr/bin/php
<?php
@ -998,8 +1009,9 @@ This is a command line PHP script with one option.
}
?>
]]>
</programlisting>
</example>
</programlisting>
</example>
</para>
<para>
In the script above, we used the special first line to indicate
that this file should be run by PHP. We work with a CLI version
@ -1024,12 +1036,14 @@ This is a command line PHP script with one option.
<literal>script.php -h</literal>. On Windows, you can make a
batch file for this task:
</para>
<example>
<title>Batch file to run a command line PHP script (script.bat)</title>
<programlisting role="winbat">
<para>
<example>
<title>Batch file to run a command line PHP script (script.bat)</title>
<programlisting role="shell">
@c:\php\cli\php.exe script.php %1 %2 %3 %4
</programlisting>
</example>
</programlisting>
</example>
</para>
<para>
Assuming you named the above program
<filename>script.php</filename>, and you have your

View file

@ -1,19 +1,18 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.14 $ -->
<!-- $Revision: 1.15 $ -->
<chapter id="features.cookies">
<title>Cookies</title>
<para>
PHP transparently supports HTTP cookies. Cookies are a mechanism
for storing data in the remote browser and thus tracking
or identifying return users. You can set cookies using the
<function>setcookie</function> function. Cookies are part of the
HTTP header, so <function>setcookie</function> must be called before
any output is sent to the browser. This is the same limitation that
<function>header</function> has. You can use the <link
linkend="ref.outcontrol">output buffering functions</link> to delay the
script output until you have decided whether or not to set any cookies or
send any headers.
PHP transparently supports HTTP cookies. Cookies are a mechanism for
storing data in the remote browser and thus tracking or identifying return
users. You can set cookies using the <function>setcookie</function>
function. Cookies are part of the HTTP header, so
<function>setcookie</function> must be called before any output is sent to
the browser. This is the same limitation that <function>header</function>
has. You can use the <link linkend="ref.outcontrol">output buffering
functions</link> to delay the script output until you have decided whether
or not to set any cookies or send any headers.
</para>
<para>
@ -21,14 +20,15 @@
PHP variable just like GET and POST method data, depending on the
<literal>register_globals</literal> and <literal>variables_order</literal>
configuration variables. If you wish to assign multiple values to a single
cookie, just add <emphasis>[]</emphasis> to the cookie name.
cookie, just add <literal>[]</literal> to the cookie name.
</para>
<para>
In PHP 4.1.0 and later, the <varname>$_COOKIE</varname> auto-global
array will always be set with any cookies sent from the client.
In PHP 4.1.0 and later, the <varname>$_COOKIE</varname> auto-global array
will always be set with any cookies sent from the client.
<varname>$HTTP_COOKIE_VARS</varname> is also set in earlier versions of PHP
when the <literal>track_vars</literal> configuration variable is set.
when the <literal>track_vars</literal> configuration variable is set. (This
setting is always on since PHP 4.0.3.)
</para>
<para>