php-doc-en/functions/misc.xml
Egon Schmid 5ea48ac3da Some typos in the english part.
Made some links in the english and german part.
Made 4 new chapters available for the german manual.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@22030 c90b9560-bf6c-de11-be94-00142212c4b1
2000-03-27 21:35:23 +00:00

1098 lines
34 KiB
XML

<reference id="ref.misc">
<title>Miscellaneous functions</title>
<titleabbrev>Misc.</titleabbrev>
<partintro>
<para>
These functions were placed here because none of the other
categories seemed to fit.
</para>
</partintro>
<refentry id="function.connection-aborted">
<refnamediv>
<refname>connection_aborted</refname>
<refpurpose>Returns true if client disconnected</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>connection_aborted</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcsynopsis>
<simpara>
Returns true if client disconnected. See the <link
linkend="features.connection-handling">Connection Handling</link>
description in the <link linkend="features">Features</link>
chapter for a complete explanation.
</simpara>
</refsect1>
</refentry>
<refentry id="function.connection-status">
<refnamediv>
<refname>connection_status</refname>
<refpurpose>Returns connection status bitfield</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>connection_status</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcsynopsis>
<simpara>
Returns the connection status bitfield. See the <link
linkend="features.connection-handling">Connection Handling</link>
description in the <link linkend="features">Features</link>
chapter for a complete explanation.
</simpara>
</refsect1>
</refentry>
<refentry id="function.connection-timeout">
<refnamediv>
<refname>connection_timeout</refname>
<refpurpose>Return true if script timed out</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>connection_timeout</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcsynopsis>
<simpara>
Returns true if script timed out. See the <link
linkend="features.connection-handling">Connection Handling</link>
description in the <link linkend="features">Features</link>
chapter for a complete explanation.
</simpara>
</refsect1>
</refentry>
<refentry id="function.define">
<refnamediv>
<refname>define</refname>
<refpurpose>Defines a named constant.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>define</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
<paramdef>int
<parameter><optional>case_insensitive</optional></parameter>
</paramdef>
</funcsynopsis>
<para>
Defines a named constant, which is similar to a variable except:
<itemizedlist>
<listitem>
<simpara>
Constants do not have a dollar sign '$' before them;
</simpara>
</listitem>
<listitem>
<simpara>
Constants may be accessed anywhere without regard to variable
scoping rules;
</simpara>
</listitem>
<listitem>
<simpara>
Constants may not be redefined or undefined once they have
been set; and
</simpara>
</listitem>
<listitem>
<simpara>
Constants may only evaluate to scalar values.
</simpara>
</listitem>
</itemizedlist>
</para>
<para>
The name of the constant is given by <parameter>name</parameter>;
the value is given by <parameter>value</parameter>.
</para>
<para>
The optional third parameter
<parameter>case_insensitive</parameter> is also available. If the
value <emphasis>1</emphasis> is given, then the constant will be
defined case-insensitive. The default behaviour is
case-sensitive; i.e. CONSTANT and Constant represent different
values.
</para>
<para>
<example>
<title>Defining Constants</title>
<programlisting role="php">
&lt;?php
define ("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
?&gt;
</programlisting>
</example>
</para>
<para>
<function>Define</function> returns TRUE on success and FALSE if
an error occurs.
</para>
<para>
See also <function>defined</function> and the section on <link
linkend="language.constants">Constants</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.defined">
<refnamediv>
<refname>defined</refname>
<refpurpose>
Checks whether a given named constant exists
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>defined</function></funcdef>
<paramdef>string <parameter>name</parameter></paramdef>
</funcsynopsis>
<para>
Returns true if the named constant given by
<parameter>name</parameter> has been defined, false otherwise.
</para>
<para>
See also <function>define</function> and the section on <link
linkend="language.constants">Constants</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.die">
<refnamediv>
<refname>die</refname>
<refpurpose>
Output a message and terminate the current script
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>die</function></funcdef>
<paramdef>string <parameter>message</parameter></paramdef>
</funcsynopsis>
<simpara>
This language construct outputs a message and terminates parsing
of the script. It does not return anything.
</simpara>
<para>
<example>
<title>die example</title>
<programlisting role="php">
&lt;?php
$filename = '/path/to/data-file';
$file = fopen ($filename, 'r')
or die("unable to open file ($filename)");
?&gt;
</programlisting>
</example>
</para>
<simpara>
See also <function>exit</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.eval">
<refnamediv>
<refname>eval</refname>
<refpurpose>Evaluate a string as PHP code</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>eval</function></funcdef>
<paramdef>string <parameter>code_str</parameter></paramdef>
</funcsynopsis>
<simpara>
<function>eval</function> evaluates the string given in
<parameter>code_str</parameter> as PHP code. Among other things,
this can be useful for storing code in a database text field for
later execution.
</simpara>
<simpara>
There are some factors to keep in mind when using
<function>eval</function>. Remember that the string passed must
be valid PHP code, including things like terminating statements
with a semicolon so the parser doesn't die on the line after the
<function>eval</function>, and properly escaping things in
<parameter>code_str</parameter>.
</simpara>
<simpara>
Also remember that variables given values under
<function>eval</function> will retain these values in the main
script afterwards.
</simpara>
<para>
<example>
<title>
<function>Eval</function> example - simple text merge
</title>
<programlisting role="php">
&lt;?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.&lt;br&gt;';
echo $str;
eval ("\$str = \"$str\";");
echo $str;
?&gt;
</programlisting>
</example>
</para>
<para>
The above example will show:
<programlisting>
This is a $string with my $name in it.
This is a cup with my coffee in it.
</programlisting>
</para>
</refsect1>
</refentry>
<refentry id="function.exit">
<refnamediv>
<refname>exit</refname>
<refpurpose>Terminate current script</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>exit</function></funcdef>
<void/>
</funcsynopsis>
<simpara>
This language construct terminates parsing of the script. It
does not return.
</simpara>
<simpara>
See also <function>die</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.func-get-arg">
<refnamediv>
<refname>func_get_arg</refname>
<refpurpose>Return an item from the argument list</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>func_get_arg</function></funcdef>
<paramdef>int <parameter>arg_num</parameter></paramdef>
</funcsynopsis>
<simpara>
Returns the argument which is at the
<parameter>arg_num</parameter>'th offset into a user-defined
function's argument list. Function arguments are counted starting
from zero. <function>Func_get_arg</function> will generate a
warning if called from outside of a function definition.
</simpara>
<simpara>
If <parameter>arg_num</parameter> is greater than the number of
arguments actually passed, a warning will be generated and
<function>func_get_arg</function> will return FALSE.
</simpara>
<para>
<informalexample>
<programlisting role="php">
&lt;?php
function foo() {
$numargs = func_num_args();
echo "Number of arguments: $numargs&lt;br&gt;\n";
if ($numargs &gt;= 2) {
echo "Second argument is: " . func_get_arg (1) . "&lt;br&gt;\n";
}
}
foo (1, 2, 3);
?&gt;
</programlisting>
</informalexample>
</para>
<simpara>
<function>Func_get_arg</function> may be used in conjunction with
<function>func_num_args</function> and
<function>func_get_args</function> to allow user-defined
functions to accept variable-length argument lists.
</simpara>
<note>
<simpara>
This function was added in PHP 4.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.func-get-args">
<refnamediv>
<refname>func_get_args</refname>
<refpurpose>
Returns an array comprising a function's argument list
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>func_get_args</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcsynopsis>
<simpara>
Returns an array in which each element is the corresponding
member of the current user-defined function's argument
list. <function>Func_get_args</function> will generate a warning
if called from outside of a function definition.
</simpara>
<para>
<informalexample>
<programlisting role="php">
&lt;?php
function foo() {
$numargs = func_num_args();
echo "Number of arguments: $numargs&lt;br&gt;\n";
if ($numargs &gt;= 2) {
echo "Second argument is: " . func_get_arg (1) . "&lt;br&gt;\n";
}
$arg_list = func_get_args();
for ($i = 0; $i &lt; $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "&lt;br&gt;\n";
}
}
foo (1, 2, 3);
?&gt;
</programlisting>
</informalexample>
</para>
<simpara>
<function>Func_get_args</function> may be used in conjunction
with <function>func_num_args</function> and
<function>func_get_arg</function> to allow user-defined functions
to accept variable-length argument lists.
</simpara>
<note>
<simpara>
This function was added in PHP 4.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.func-num-args">
<refnamediv>
<refname>func_num_args</refname>
<refpurpose>
Returns the number of arguments passed to the function
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>func_num_args</function></funcdef>
<paramdef>void <parameter></parameter></paramdef>
</funcsynopsis>
<simpara>
Returns the number of arguments passed into the current
user-defined function. <function>Func_num_args</function> will
generate a warning if called from outside of a function
definition.
</simpara>
<para>
<informalexample>
<programlisting role="php">
&lt;?php
function foo() {
$numargs = func_num_args();
echo "Number of arguments: $numargs\n";
}
foo (1, 2, 3); // Prints 'Number of arguments: 3'
?&gt;
</programlisting>
</informalexample>
</para>
<simpara>
<function>Func_num_args</function> may be used in conjunction
with <function>func_get_arg</function> and
<function>func_get_args</function> to allow user-defined
functions to accept variable-length argument lists.
</simpara>
<note>
<simpara>
This function was added in PHP 4.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.function-exists">
<refnamediv>
<refname>function_exists</refname>
<refpurpose>
Return true if the given function has been defined
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>function_exists</function></funcdef>
<paramdef>string <parameter>function_name</parameter></paramdef>
</funcsynopsis>
<simpara>
Checks the list of defined functions for
<parameter>function_name</parameter>. Returns true if the given
function name was found, false otherwise.
</simpara>
</refsect1>
</refentry>
<refentry id="function.get-browser">
<refnamediv>
<refname>get_browser</refname>
<refpurpose>
Tells what the user's browser is capable of
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>object <function>get_browser</function></funcdef>
<paramdef>string
<parameter><optional>user_agent</optional></parameter>
</paramdef>
</funcsynopsis>
<simpara>
<function>get_browser</function> attempts to determine the
capabilities of the user's browser. This is done by looking up
the browser's information in the
<filename>browscap.ini</filename> file. By default, the value of
$HTTP_USER_AGENT is used; however, you can alter this (i.e., look
up another browser's info) by passing the optional
<parameter>user_agent</parameter> parameter to
<function>get_browser</function>.
</simpara>
<simpara>
The information is returned in an object, which will contain
various data elements representing, for instance, the browser's
major and minor version numbers and ID string; true/false values
for features such as frames, JavaScript, and cookies; and so
forth.
</simpara>
<simpara>
While <filename>browscap.ini</filename> contains information on
many browsers, it relies on user updates to keep the database
current. The format of the file is fairly self-explanatory.
</simpara>
<para>
The following example shows how one might list all available
information retrieved about the user's browser.
<example>
<title><function>Get_browser</function> example</title>
<programlisting role="php">
&lt;?php
function list_array ($array) {
while (list ($key, $value) = each ($array)) {
$str .= "&lt;b&gt;$key:&lt;/b&gt; $value&lt;br&gt;\n";
}
return $str;
}
echo "$HTTP_USER_AGENT&lt;hr&gt;\n";
$browser = get_browser();
echo list_array ((array) $browser);
?&gt;
</programlisting>
</example>
</para>
<simpara>
The output of the above script would look something like this:
</simpara>
<programlisting>
Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)&lt;hr&gt;
&lt;b&gt;browser_name_pattern:&lt;/b&gt; Mozilla/4\.5.*&lt;br&gt;
&lt;b&gt;parent:&lt;/b&gt; Netscape 4.0&lt;br&gt;
&lt;b&gt;platform:&lt;/b&gt; Unknown&lt;br&gt;
&lt;b&gt;majorver:&lt;/b&gt; 4&lt;br&gt;
&lt;b&gt;minorver:&lt;/b&gt; 5&lt;br&gt;
&lt;b&gt;browser:&lt;/b&gt; Netscape&lt;br&gt;
&lt;b&gt;version:&lt;/b&gt; 4&lt;br&gt;
&lt;b&gt;frames:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;tables:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;cookies:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;backgroundsounds:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;vbscript:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;javascript:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;javaapplets:&lt;/b&gt; 1&lt;br&gt;
&lt;b&gt;activexcontrols:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;beta:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;crawler:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;authenticodeupdate:&lt;/b&gt; &lt;br&gt;
&lt;b&gt;msn:&lt;/b&gt; &lt;br&gt;
</programlisting>
<simpara>
In order for this to work, your <link
linkend="ini.sect.browscap">browscap</link> configuration file
setting must point to the correct location of the
<filename>browscap.ini</filename> file.
</simpara>
<simpara>
For more information (including locations from which you may
obtain a <filename>browscap.ini</filename> file), check the PHP
FAQ at <ulink
url="&url.php.faq;">&url.php.faq;</ulink>.
</simpara>
<note>
<simpara>
Browscap support was added to PHP in version 3.0b2.
</simpara>
</note>
</refsect1>
</refentry>
<refentry id="function.ignore-user-abort">
<refnamediv>
<refname>ignore_user_abort</refname>
<refpurpose>
Set whether a client disconnect should abort script execution
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>ignore_user_abort</function></funcdef>
<paramdef>int
<parameter><optional>setting</optional></parameter>
</paramdef>
</funcsynopsis>
<simpara>
This function sets whether a client disconnect should cause a
script to be aborted. It will return the previous setting and
can be called without an argument to not change the current
setting and only return the current setting. See the <link
linkend="features.connection-handling">Connection Handling</link>
section in the <link linkend="features">Features</link> chapter
for a complete description of connection handling in PHP.
</simpara>
</refsect1>
</refentry>
<refentry id="function.iptcparse">
<refnamediv>
<refname>iptcparse</refname>
<refpurpose>
Parse a binary IPTC <ulink url="&url.iptc;">&url.iptc;</ulink>
block into single tags.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>array <function>iptcparse</function></funcdef>
<paramdef>string <parameter>iptcblock</parameter></paramdef>
</funcsynopsis>
<simpara>
This function parses a binary IPTC block into its single tags. It
returns an array using the tagmarker as an index and the value as
the value. It returns false on error or if no IPTC data was
found. See <function>GetImageSize</function> for a sample.
</simpara>
</refsect1>
</refentry>
<refentry id="function.leak">
<refnamediv>
<refname>leak</refname>
<refpurpose>Leak memory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>leak</function></funcdef>
<paramdef>int <parameter>bytes</parameter></paramdef>
</funcsynopsis>
<simpara>
<function>Leak</function> leaks the specified amount of memory.
</simpara>
<simpara>
This is useful when debugging the memory manager, which
automatically cleans up "leaked" memory when each request is
completed.
</simpara>
</refsect1>
</refentry>
<refentry id="function.pack">
<refnamediv>
<refname>pack</refname>
<refpurpose>Pack data into binary string.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>pack</function></funcdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>mixed
<parameter><optional>args</optional></parameter> ...
</paramdef>
</funcsynopsis>
<para>
Pack given arguments into binary string according to
<parameter>format</parameter>. Returns binary string containing
data.
</para>
<para>
The idea to this function was taken from Perl and all formatting
codes work the same as there, however, there are some formatting
codes that are missing such as Perl's "u" format code. The format
string consists of format codes followed by an optional repeater
argument. The repeater argument can be either an integer value or
* for repeating to the end of the input data. For a, A, h, H the
repeat count specifies how many characters of one data argument
are taken, for @ it is the absolute position where to put the
next data, for everything else the repeat count specifies how
many data arguments are consumed and packed into the resulting
binary string. Currently implemented are
<itemizedlist>
<listitem>
<simpara>
a NUL-padded string
</simpara>
</listitem>
<listitem>
<simpara>
A SPACE-padded string
</simpara>
</listitem>
<listitem>
<simpara>
h Hex string, low nibble first
</simpara>
</listitem>
<listitem>
<simpara>
H Hex string, high nibble first
</simpara>
</listitem>
<listitem>
<simpara>
c signed char
</simpara>
</listitem>
<listitem>
<simpara>
C unsigned char
</simpara>
</listitem>
<listitem>
<simpara>
s signed short (always 16 bit, machine byte order)
</simpara>
</listitem>
<listitem>
<simpara>
S unsigned short (always 16 bit, machine byte order)
</simpara>
</listitem>
<listitem>
<simpara>
n unsigned short (always 16 bit, big endian byte order)
</simpara>
</listitem>
<listitem>
<simpara>
v unsigned short (always 16 bit, little endian byte order)
</simpara>
</listitem>
<listitem>
<simpara>
i signed integer (machine dependant size and byte order)
</simpara>
</listitem>
<listitem>
<simpara>
I unsigned integer (machine dependant size and byte order)
</simpara>
</listitem>
<listitem>
<simpara>
l signed long (always 32 bit, machine byte order)
</simpara>
</listitem>
<listitem>
<simpara>
L unsigned long (always 32 bit, machine byte order)
</simpara>
</listitem>
<listitem>
<simpara>
N unsigned long (always 32 bit, big endian byte order)
</simpara>
</listitem>
<listitem>
<simpara>
V unsigned long (always 32 bit, little endian byte order)
</simpara>
</listitem>
<listitem>
<simpara>
f float (machine dependent size and representation)
</simpara>
</listitem>
<listitem>
<simpara>
d double (machine dependent size and representation)
</simpara>
</listitem>
<listitem>
<simpara>
x NUL byte
</simpara>
</listitem>
<listitem>
<simpara>X Back up one byte
</simpara>
</listitem>
<listitem>
<simpara>@ NUL-fill to absolute position
</simpara>
</listitem>
</itemizedlist>
<example>
<title><function>Pack</function> format string</title>
<programlisting role="php">
$binarydata = pack ("nvc*", 0x1234, 0x5678, 65, 66);
</programlisting>
<para>
The resulting binary string will be 6 bytes long and contain
the byte sequence 0x12, 0x34, 0x78, 0x56, 0x41, 0x42.
</para>
</example>
</para>
<para>
Note that the distinction between signed and unsigned values only
affects the function <function>unpack</function>, where as
function <function>pack</function> gives the same result for
signed and unsigned format codes.
</para>
<para>
Also note that PHP internally stores integral values as signed
values of a machine dependant size. If you give it an unsigned
integral value too large to be stored that way it is converted to
a double which often yields an undesired result.
</para>
</refsect1>
</refentry>
<refentry id="function.register-shutdown-function">
<refnamediv>
<refname>register_shutdown_function</refname>
<refpurpose>
Register a function for execution on shutdown
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int
<function>register_shutdown_function</function>
</funcdef>
<paramdef>string <parameter>func</parameter></paramdef>
</funcsynopsis>
<simpara>
Registers the function named by <parameter>func</parameter> to be
executed when script processing is complete.</simpara>
<para>
Common Pitfalls:
</para>
<simpara>
Since no output is allowed to the browser in this function, you
will be unable to debug it using statements such as print or
echo.
</simpara>
</refsect1>
</refentry>
<refentry id="function.serialize">
<refnamediv>
<refname>serialize</refname>
<refpurpose>
Generates a storable representation of a value
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>serialize</function></funcdef>
<paramdef>mixed <parameter>value</parameter></paramdef>
</funcsynopsis>
<simpara>
<function>Serialize</function> returns a string containing a
byte-stream representation of <parameter>value</parameter> that
can be stored anywhere.
</simpara>
<simpara>
This is useful for storing or passing PHP values around without
losing their type and structure.
</simpara>
<simpara>
To make the serialized string into a PHP value again, use
<function>unserialize</function>. <function>Serialize</function>
handles the types <type>integer</type>, <type>double</type>,
<type>string</type>, <type>array</type> (multidimensional) and
<type>object</type> (object properties will be serialized, but
methods are lost).
</simpara>
<para>
<example>
<title><function>Serialize</function> example</title>
<programlisting role="php">
// $session_data contains a multi-dimensional array with session
// information for the current user. We use serialize() to store
// it in a database at the end of the request.
$conn = odbc_connect ("webdb", "php", "chicken");
$stmt = odbc_prepare ($conn,
"UPDATE sessions SET data = ? WHERE id = ?");
$sqldata = array (serialize($session_data), $PHP_AUTH_USER);
if (!odbc_execute ($stmt, &$sqldata)) {
$stmt = odbc_prepare($conn,
"INSERT INTO sessions (id, data) VALUES(?, ?)");
if (!odbc_execute($stmt, &$sqldata)) {
/* Something went wrong. Bitch, whine and moan. */
}
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.sleep">
<refnamediv>
<refname>sleep</refname>
<refpurpose>Delay execution</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>sleep</function></funcdef>
<paramdef>int <parameter>seconds</parameter></paramdef>
</funcsynopsis>
<simpara>
The sleep function delays program execution for the given number
of <parameter>seconds</parameter>.
</simpara>
<simpara>
See also <function>usleep</function>.
</simpara>
</refsect1>
</refentry>
<refentry id="function.uniqid">
<refnamediv>
<refname>uniqid</refname>
<refpurpose>Generate a unique id</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>uniqid</function></funcdef>
<paramdef>string <parameter>prefix</parameter></paramdef>
<paramdef>boolean
<parameter><optional>lcg</optional></parameter>
</paramdef>
</funcsynopsis>
<simpara>
<function>Uniqid</function> returns a prefixed unique identifier
based on the current time in microseconds. The prefix can be
useful for instance if you generate identifiers simultaneously on
several hosts that might happen to generate the identifier at the
same microsecond. <parameter>Prefix</parameter> can be up to 114
characters long.
</simpara>
<simpara>
If the optional <parameter>lcg</parameter> parameter is true,
<function>uniqid</function> will add additional "combined LCG"
entropy at the end of the return value, which should make the
results more unique.
</simpara>
<simpara>
With an empty <parameter>prefix</parameter>, the returned string
will be 13 characters long. If <parameter>lcg</parameter> is
true, it will be 23 characters.
</simpara>
<note>
<simpara>
The <parameter>lcg</parameter> parameter is only available in
PHP 4 and PHP 3.0.13 and later.
</simpara>
</note>
<para>
If you need a unique identifier or token and you intend to give
out that token to the user via the network (i.e. session cookies),
it is recommended that you use something along the lines of
<informalexample>
<programlisting role="php">
$token = md5 (uniqid ("")); // no random portion
$better_token = md5 (uniqid (rand())); // better, difficult to guess
</programlisting>
</informalexample>
</para>
<simpara>
This will create a 32 character identifier (a 128 bit hex number)
that is extremely difficult to predict.
</simpara>
</refsect1>
</refentry>
<refentry id="function.unpack">
<refnamediv>
<refname>unpack</refname>
<refpurpose>Unpack data from binary string</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>array <function>unpack</function></funcdef>
<paramdef>string <parameter>format</parameter></paramdef>
<paramdef>string <parameter>data</parameter></paramdef>
</funcsynopsis>
<para>
<function>Unpack</function> from binary string into array
according to <parameter>format</parameter>. Returns array
containing unpacked elements of binary string.
</para>
<para>
<function>Unpack</function> works slightly different from Perl as
the unpacked data is stored in an associative array. To
accomplish this you have to name the different format codes and
separate them by a slash /.
<example>
<title><function>Unpack</function> format string</title>
<programlisting role="php">
$array = unpack ("c2chars/nint", $binarydata);
</programlisting>
<para>
The resulting array will contain the entries "chars1",
"chars2" and "int".
</para>
</example>
</para>
<para>
For an explanation of the format codes see also:
<function>pack</function>
</para>
<para>
Note that PHP internally stores integral values as signed. If you
unpack a large unsigned long and it is of the same size as PHP
internally stored values the result will be a negative number
even though unsigned unpacking was specified.
</para>
</refsect1>
</refentry>
<refentry id="function.unserialize">
<refnamediv>
<refname>unserialize</refname>
<refpurpose>
Creates a PHP value from a stored representation
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>mixed <function>unserialize</function></funcdef>
<paramdef>string <parameter>str</parameter></paramdef>
</funcsynopsis>
<simpara>
<function>unserialize</function> takes a single serialized
variable (see <function>serialize</function>) and converts it
back into a PHP value. The converted value is returned, and can
be an <type>integer</type>, <type>double</type>,
<type>string</type>, <type>array</type> or <type>object</type>.
If an object was serialized, its methods are not preserved in the
returned value.
</simpara>
<para>
<example>
<title><function>Unserialize</function> example</title>
<programlisting role="php">
// Here, we use unserialize() to load session data from a database
// into $session_data. This example complements the one described
// with <function>serialize</function>.
$conn = odbc_connect ("webdb", "php", "chicken");
$stmt = odbc_prepare ($conn, "SELECT data FROM sessions WHERE id = ?");
$sqldata = array ($PHP_AUTH_USER);
if (!odbc_execute ($stmt, &$sqldata) || !odbc_fetch_into ($stmt, &$tmp)) {
// if the execute or fetch fails, initialize to empty array
$session_data = array();
} else {
// we should now have the serialized data in $tmp[0].
$session_data = unserialize ($tmp[0]);
if (!is_array ($session_data)) {
// something went wrong, initialize to empty array
$session_data = array();
}
}
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.usleep">
<refnamediv>
<refname>usleep</refname>
<refpurpose>Delay execution in microseconds</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>usleep</function></funcdef>
<paramdef>int <parameter>micro_seconds</parameter></paramdef>
</funcsynopsis>
<simpara>
The <function>sleep</function> function delays program execution
for the given number of <parameter>micro_seconds</parameter>.
</simpara>
<simpara>
See also <function>sleep</function>.
</simpara>
<note>
<simpara>
This function does not work on Windows systems.
</simpara>
</note>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->