php-doc-en/reference/sockets/functions/socket-strerror.xml
Máté Kocsis 14dc7c4736 Generate sockets methodsynopses based on stubs
Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>

Closes GH-311.
2021-01-10 19:04:58 +01:00

119 lines
3.2 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.socket-strerror" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>socket_strerror</refname>
<refpurpose>Return a string describing a socket error</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>socket_strerror</methodname>
<methodparam><type>int</type><parameter>error_code</parameter></methodparam>
</methodsynopsis>
<para>
<function>socket_strerror</function> takes as its
<parameter>error_code</parameter> parameter a socket error code as returned by
<function>socket_last_error</function> and returns the corresponding
explanatory text.
</para>
<note>
<para>
Although the error messages generated by the socket extension are in
English, the system messages retrieved with this function will appear
depending on the current locale (<constant>LC_MESSAGES</constant>).
</para>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>error_code</parameter></term>
<listitem>
<para>
A valid socket error number, likely produced by
<function>socket_last_error</function>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the error message associated with the <parameter>error_code</parameter>
parameter.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>socket_strerror</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
if (false == ($socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}
if (false == (@socket_bind($socket, '127.0.0.1', 80))) {
echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($socket)) . "\n";
}
?>
]]>
</programlisting>
<para>
The expected output from the above example (assuming the script
is not run with root privileges):
</para>
<screen>
<![CDATA[
socket_bind() failed: reason: Permission denied
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>socket_accept</function></member>
<member><function>socket_bind</function></member>
<member><function>socket_connect</function></member>
<member><function>socket_listen</function></member>
<member><function>socket_create</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- 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
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->