mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-26 22:08:55 +00:00

closing tags and attribute quotes, but lets a stock 3.1 install compile the PHP docs. It still compiles with DocBook 3.0, as well. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@14693 c90b9560-bf6c-de11-be94-00142212c4b1
805 lines
27 KiB
Text
805 lines
27 KiB
Text
<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>
|
|
<?php
|
|
define("CONSTANT", "Hello world.");
|
|
echo CONSTANT; // outputs "Hello world."
|
|
?>
|
|
</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.</simpara>
|
|
<para>
|
|
<example>
|
|
<title>die example</title>
|
|
<programlisting>
|
|
<?php
|
|
$filename = '/path/to/data-file';
|
|
$file = fopen($filename, 'r')
|
|
or die "unable to open file ($filename)";
|
|
?>
|
|
</programlisting>
|
|
</example></para>
|
|
</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>eval() example - simple text merge</title>
|
|
<programlisting>
|
|
<?php
|
|
$string = 'cup';
|
|
$name = 'coffee';
|
|
$str = 'This is a $string with my $name in it.<br>';
|
|
echo $str;
|
|
eval( "\$str = \"$str\";" );
|
|
echo $str;
|
|
?>
|
|
</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>
|
|
</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>
|
|
<?php
|
|
function list_array( $array ) {
|
|
while ( list( $key, $value ) = each( $array ) ) {
|
|
$str .= "<b>$key:</b> $value<br>\n";
|
|
}
|
|
return $str;
|
|
}
|
|
echo "$HTTP_USER_AGENT<hr>\n";
|
|
$browser = get_browser();
|
|
echo list_array( (array) $browser );
|
|
?>
|
|
</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)<hr>
|
|
<b>browser_name_pattern:</b> Mozilla/4\.5.*<br>
|
|
<b>parent:</b> Netscape 4.0<br>
|
|
<b>platform:</b> Unknown<br>
|
|
<b>majorver:</b> 4<br>
|
|
<b>minorver:</b> 5<br>
|
|
<b>browser:</b> Netscape<br>
|
|
<b>version:</b> 4<br>
|
|
<b>frames:</b> 1<br>
|
|
<b>tables:</b> 1<br>
|
|
<b>cookies:</b> 1<br>
|
|
<b>backgroundsounds:</b> <br>
|
|
<b>vbscript:</b> <br>
|
|
<b>javascript:</b> 1<br>
|
|
<b>javaapplets:</b> 1<br>
|
|
<b>activexcontrols:</b> <br>
|
|
<b>beta:</b> <br>
|
|
<b>crawler:</b> <br>
|
|
<b>authenticodeupdate:</b> <br>
|
|
<b>msn:</b> <br>
|
|
</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;">http://www.php.net/FAQ.html</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 Connection
|
|
Handling section in the Features 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="http://www.xe.net/iptc/">
|
|
http://www.xe.net/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. 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>pack 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>serialize 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>
|
|
$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>
|
|
Unpack from binary string into array according to
|
|
<parameter>format</parameter>. Returns array containing unpacked
|
|
elements of binary string.</para>
|
|
|
|
<para>
|
|
Unpack 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>unpack 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>unserialize 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 sleep function delays program execution for the given number
|
|
of <parameter>micro_seconds</parameter>.</simpara>
|
|
<simpara>
|
|
See also <function>sleep</function>.</simpara>
|
|
</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:
|
|
-->
|