📄 context.socket.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Socket context option listing</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="context.html">Context options and parameters</a></div> <div class="next" style="text-align: right; float: right;"><a href="context.http.html">HTTP context options</a></div> <div class="up"><a href="context.html">Context options and parameters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="context.socket" class="refentry"> <div class="refnamediv"> <h1 class="refname">Socket context options</h1> <p class="refpurpose"><span class="refname">Socket context options</span> — <span class="dc-title">Socket context option listing</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <p class="para"> Socket context options are available for all wrappers that work over sockets, like <i>tcp</i>, <i>http</i> and <i>ftp</i>. </p> </div> <div class="refsect1 options"> <h3 class="title">Options</h3> <p class="para"> <dl> <dt id="context.socket.bindto"> <span class="term"><i><tt class="parameter">bindto</tt></i></span> <dd> <p class="para"> Used to specify the IP address (either IPv4 or IPv6) and/or the port number that PHP will use to access the network. The syntax is <i>ip:port</i>. Setting the IP or the port to <i>0</i> will let the system choose the IP and/or port. </p> <blockquote><p><b class="note">Note</b>: As FTP creates two socket connections during normal operation, the port number cannot be specified using this option. <br /> </p></blockquote> </dd> </dt> </dl> </p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.1.0</td> <td colspan="1" rowspan="1" align="left"> Added <i>bindto</i>. </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="context.socket.example-bindto" name="context.socket.example-bindto"> <p><b>Example #1 Basic <i><tt class="parameter">bindto</tt></i> usage example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// connect to the internet using the '192.168.0.100' IP<br /></span><span style="color: #0000BB">$opts </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'socket' </span><span style="color: #007700">=> array(<br /> </span><span style="color: #DD0000">'bindto' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'192.168.0.100:0'</span><span style="color: #007700">,<br /> ),<br />);<br /><br /><br /></span><span style="color: #FF8000">// connect to the internet using the '192.168.0.100' IP and port '7000'<br /></span><span style="color: #0000BB">$opts </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'socket' </span><span style="color: #007700">=> array(<br /> </span><span style="color: #DD0000">'bindto' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'192.168.0.100:7000'</span><span style="color: #007700">,<br /> ),<br />);<br /><br /><br /></span><span style="color: #FF8000">// connect to the internet using port '7000'<br /></span><span style="color: #0000BB">$opts </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'socket' </span><span style="color: #007700">=> array(<br /> </span><span style="color: #DD0000">'bindto' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'0:7000'</span><span style="color: #007700">,<br /> ),<br />);<br /><br /><br /></span><span style="color: #FF8000">// create the context...<br /></span><span style="color: #0000BB">$context </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(</span><span style="color: #0000BB">$opts</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// ...and use it to fetch the data<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">, </span><span style="color: #0000BB">$context</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="context.html">Context options and parameters</a></div> <div class="next" style="text-align: right; float: right;"><a href="context.http.html">HTTP context options</a></div> <div class="up"><a href="context.html">Context options and parameters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -