Home > php教程 > php手册 > 详解PHP fsockopen的使用方法

详解PHP fsockopen的使用方法

WBOY
Release: 2016-06-13 11:09:07
Original
1498 people have browsed it

还有一个以curl_开头的函数,可以实现很多功能。有时间要好好研究!下面是关于fscokopen的介绍

1.PHP fsockopen函数说明:

Open Internet or Unix domain socket connection(打开套接字链接)

Initiates a socket connection to the resource specified by target .

fsockopen() returns a file pointer which may be used together with the other file functions (such as fgets() , fgetss() , fwrite() , fclose() , and feof() ).就是返回一个文件句柄

开启PHP fsockopen这个函数

PHP fsockopen需要 PHP.ini 中 allow_url_fopen 选项开启。
 

<ol class="dp-xml">
<li class="alt"><span><span>$</span><span class="attribute">fp</span><span> = </span><span class="attribute-value">fsockopen</span><span>("www.example.com",<br> 80, $errno, $errstr, 30);   </span></span></li>
<li><span>if (!$fp) {   </span></li>
<li class="alt">
<span>echo "$errstr ($errno)</span><span class="tag"><span class="tag-name">br</span><span> </span><span class="tag">/></span><span>n";   </span></span>
</li>
<li><span>} else {   </span></li>
<li class="alt">
<span>$</span><span class="attribute">out</span><span> = </span><span class="attribute-value">"GET / HTTP/1.1rn"</span><span>;   </span>
</li>
<li>
<span>$out </span><span class="attribute">.</span><span>= </span><span class="attribute-value">"Host: www.example.comrn"</span><span>;   </span>
</li>
<li class="alt">
<span>$out </span><span class="attribute">.</span><span>= </span><span class="attribute-value">"Connection: Closernrn"</span><span>;   </span>
</li>
<li><span> </span></li>
<li class="alt"><span>fwrite($fp, $out);   </span></li>
<li><span>while (!feof($fp)) {   </span></li>
<li class="alt"><span>echo fgets($fp, 128);   </span></li>
<li><span>}   </span></li>
<li class="alt"><span>fclose($fp);   </span></li>
<li><span>}  </span></li>
</ol>
Copy after login

以上就是PHP fsockopen函数的具体使用方法,供大家参考学习。


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template