mirror of
https://github.com/php/doc-es.git
synced 2026-03-25 16:02:13 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@334646 c90b9560-bf6c-de11-be94-00142212c4b1
237 lines
7.7 KiB
XML
237 lines
7.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 8b5940cadeb4f1c8492f4a7f70743a2be807cf39 Maintainer: aeoris Status: Ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.fsockopen">
|
|
<refnamediv>
|
|
<refname>fsockopen</refname>
|
|
<refpurpose>Abre una conexión vía sockets a Internet o a un dominio Unix</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>resource</type><methodname>fsockopen</methodname>
|
|
<methodparam><type>string</type><parameter>hostname</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>port</parameter><initializer>-1</initializer></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter role="reference">errno</parameter></methodparam>
|
|
<methodparam choice="opt"><type>string</type><parameter role="reference">errstr</parameter></methodparam>
|
|
<methodparam choice="opt"><type>float</type><parameter>timeout</parameter><initializer>ini_get("default_socket_timeout")</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Inicia una conexión vía sockets al recurso especificado por
|
|
<parameter>hostname</parameter>.
|
|
</para>
|
|
<para>
|
|
PHP soporta objetivos Internet y dominios Unix tal y como se describe en
|
|
<xref linkend="transports"/>. También se puede obtener una lista de los transportes soportados
|
|
utilizando <function>stream_get_transports</function>.
|
|
</para>
|
|
<para>
|
|
El socket será abierto por defecto en modo de bloqueo. Es posible
|
|
cambiarlo a modo de no bloqueo utilizando
|
|
<function>stream_set_blocking</function>.
|
|
</para>
|
|
<para>
|
|
La función <function>stream_socket_client</function> es similar, pero
|
|
provee un conjunto más amplio de opciones, incluyendo conexión no bloqueante y la
|
|
posibilidad de proporcionar contexto a una secuencia.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>hostname</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si el soporte a OpenSSL <link linkend="openssl.installation">está
|
|
instalado</link>, puedes añadir al principio del <parameter>hostname</parameter>
|
|
tanto <literal>ssl://</literal> como <literal>tls://</literal> para
|
|
utilizar una conexión de cliente SSL o TLS sobre TCP/IP para conectar al
|
|
host remoto.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>port</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El número de puerto. Se puede omitir con
|
|
<literal>-1</literal> para transportes que no empleen puertos, como
|
|
<literal>unix://</literal>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>errno</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si se proporciona, contiene el número de error a nivel de sistema que se ha producido en la
|
|
llamada a <literal>connect()</literal> a nivel de sistema.
|
|
</para>
|
|
<para>
|
|
Si el valor devuelto en <parameter>errno</parameter> es
|
|
<literal>0</literal> y la función devuelve &false;, esto
|
|
indica que el error ocurrió antes de
|
|
la llamada a <literal>connect()</literal>. Probablemente se deba a un
|
|
problema al inicializar el socket.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>errstr</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El mensaje de error como string.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>timeout</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El tiempo límite de la conexión, en segundos.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Si fuera necesario definir un tiempo de límite para leer/escribir datos a través del
|
|
socket, se deberá utilizar <function>stream_set_timeout</function>, ya que
|
|
el parámetro <parameter>timeout</parameter> de
|
|
<function>fsockopen</function> sólo se aplica al realizar la conexión del
|
|
socket.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
<function>fsockopen</function> devuelve un puntero a fichero que puede ser utilizado
|
|
junto a otras funciones de fichero (como
|
|
<function>fgets</function>, <function>fgetss</function>,
|
|
<function>fwrite</function>, <function>fclose</function>, y
|
|
<function>feof</function>). Si la llamada falla, devolverá &false;
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
Lanza <constant>E_WARNING</constant> si el <parameter>hostname</parameter> no es
|
|
un dominio válido.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <function>fsockopen</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
|
|
if (!$fp) {
|
|
echo "$errstr ($errno)<br />\n";
|
|
} else {
|
|
$out = "GET / HTTP/1.1\r\n";
|
|
$out .= "Host: www.example.com\r\n";
|
|
$out .= "Connection: Close\r\n\r\n";
|
|
fwrite($fp, $out);
|
|
while (!feof($fp)) {
|
|
echo fgets($fp, 128);
|
|
}
|
|
fclose($fp);
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Utilización de una conexión UDP</title>
|
|
<para>
|
|
El ejemplo inferior muestra cómo obtener el día y la hora del servicio UDP
|
|
"daytime" (puerto 13) en el servidor local.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$fp = fsockopen("udp://127.0.0.1", 13, $errno, $errstr);
|
|
if (!$fp) {
|
|
echo "ERROR: $errno - $errstr<br />\n";
|
|
} else {
|
|
fwrite($fp, "\n");
|
|
echo fread($fp, 26);
|
|
fclose($fp);
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
Dependiendo del entorno, el dominio Unix o el
|
|
tiempo de expiración opcional pueden no estar disponibles.
|
|
</para>
|
|
</note>
|
|
<warning>
|
|
<para>
|
|
Los sockets UDP pueden en ocasiones aparecerán como abiertos sin errores,
|
|
incluso aunque el servidor remoto no esté disponible. El error sólo
|
|
aparecerá una vez se lean o escriban datos del/al socket.
|
|
Esto es debido a que UDP es un protoclo "sin conexión",
|
|
lo que significa que el sistema operativo no trata de establecer
|
|
un enlace con el socket hasta que realmente necesita enviar o recibir datos.
|
|
</para>
|
|
</warning>
|
|
&ipv6.brackets;
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>pfsockopen</function></member>
|
|
<member><function>stream_socket_client</function></member>
|
|
<member><function>stream_set_blocking</function></member>
|
|
<member><function>stream_set_timeout</function></member>
|
|
<member><function>fgets</function></member>
|
|
<member><function>fgetss</function></member>
|
|
<member><function>fwrite</function></member>
|
|
<member><function>fclose</function></member>
|
|
<member><function>feof</function></member>
|
|
<member><function>socket_connect</function></member>
|
|
<member>La <link linkend="ref.curl">extensión Curl</link></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
|
|
-->
|