-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfsockopen.xml
More file actions
146 lines (145 loc) · 5.63 KB
/
fsockopen.xml
File metadata and controls
146 lines (145 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?xml version="1.0" encoding="UTF-8"?>
<!-- splitted from ./it/functions/network.xml, last change in rev 1.1 -->
<!-- last change to 'fsockopen' in en/ tree in rev 1.2 -->
<!-- EN-Revision: n/a Maintainer: cortesi Status: ready -->
<!-- OLD-Revision: 1.60/EN.1.2 -->
<refentry xml:id="function.fsockopen" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>fsockopen</refname>
<refpurpose>
Apre una connessione a un socket appartenente a un dominio Internet o Unix
</refpurpose>
</refnamediv>
<refsect1>
<title>Descrizione</title>
<methodsynopsis>
<type>int</type><methodname>fsockopen</methodname>
<methodparam><type>string</type><parameter>hostname</parameter></methodparam>
<methodparam><type>int</type><parameter>porta</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>errno</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>errstr</parameter></methodparam>
<methodparam choice="opt"><type>float</type><parameter>timeout</parameter></methodparam>
</methodsynopsis>
<para>
Inizializza una connessione nel dominio Internet (AF_INET, usando TCP
o UDP) o Unix (AF_UNIX). Per il dominio Internet, apre
una connessione a un socket TCP verso l'
<parameter>hostname</parameter> sulla porta
<parameter>port</parameter>. <parameter>hostname</parameter> può essere
in questo caso, sia un fully qualified domain name o un indirizzo IP.
Per le connessioni UDP, è necessario specificare esplicitamente il
protocollo, usando: '<literal>udp://</literal>' come prefisso di
<parameter>hostname</parameter>. Per il dominio Unix,
<parameter>hostname</parameter> viene utilizzato come percorso verso il
socket, in questo caso, <parameter>porta</parameter> deve essere impostato
a 0. Il parametro opzionale <parameter>timeout</parameter> può essere
usato per impostare un timeout in secondi per la chiamata di sistema connect.
</para>
<para>
A partire da PHP 4.3.0, se si è compilato con il supporto OpenSSL, si può
prefissare <parameter>hostname</parameter> con
'<literal>ssl://</literal>' oppure '<literal>tls://</literal>' per
utilizzare una connessione client SSL o TLS su una connessione TCP/IP per connettersi
all'host remoto.
</para>
<para>
<function>fsockopen</function> restituisce un puntatore a file che può
essere usato nelle altre funzioni orientate ai file (come
<function>fgets</function>, <function>fgetss</function>,
<function>fputs</function>, <function>fclose</function> e
<function>feof</function>).
</para>
<para>
Se la chiamata non ha successo, viene restituito &false; e se gli argomenti opzionali
<parameter>errno</parameter> e <parameter>errstr</parameter>
sono presenti, vengono impostati a indicare l'errore
a livello di sistema che è avvenuto nella chiamata alla funzione
<literal>connect()</literal> del sistema operativo. Se il valore di
<parameter>errno</parameter> restituito è <literal>0</literal> e
la funzione restituisce &false;, è un'indicazione che l'errore
è avvenuto prima della chiamata di <literal>connect()</literal>. Questo è
molto probabilmente legato ad un problema di inizializzazione del socket. Si noti che
gli argomenti <parameter>errno</parameter> e
<parameter>errstr</parameter> verranno sempre passati by
reference.
</para>
<para>
A seconda dell'ambiente operativo, il dominio Unix o l'opzionale
timeout della connect potrebbero non essere disponibili.
</para>
<para>
Il socket viene aperto di default in modo blocking. Si può passare
al modo non-blocking usando
<function>socket_set_blocking</function>.
<example>
<title>Esempio di <function>fsockopen</function></title>
<programlisting role="php">
<![CDATA[
<?php
$fp = fsockopen ("www.php.net", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.0\r\nHost: www.php.net\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
]]>
</programlisting>
</example>
L'esempio seguente mostra come ottenere data e ora
tramite il servizio UDP "daytime" (porta 13) della vostra stessa macchina.
<example>
<title>Uso di connessione UDP</title>
<programlisting role="php">
<![CDATA[
<?php
$fp = fsockopen("udp://127.0.0.1", 13, $errno, $errstr);
if (!$fp) {
echo "ERRORE: $errno - $errstr<br>\n";
} else {
fwrite($fp,"\n");
echo fread($fp, 26);
fclose($fp);
}
?>
]]>
</programlisting>
</example>
<note>
<para>Il parametro timeout è stato introdotto nel PHP 3.0.9 e
il supporto UDP è stato aggiunto nel PHP 4.
</para>
</note>
Vedere anche <function>pfsockopen</function>,
<function>socket_set_blocking</function>,
<function>socket_set_timeout</function>, <function>fgets</function>,
<function>fgetss</function>, <function>fputs</function>,
<function>fclose</function>, <function>feof</function> e
l'<link linkend="ref.curl">estensione Curl</link>.
</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
-->