Home > Backend Development > PHP Tutorial > Detailed explanation of how to use PHP fsockopen_PHP tutorial

Detailed explanation of how to use PHP fsockopen_PHP tutorial

WBOY
Release: 2016-07-15 13:31:47
Original
1188 people have browsed it

There is also a function starting with curl_, which can implement many functions. Do some research when you have time! The following is an introduction to fscokopen

1. PHP fsockopen function description:

Open Internet or Unix domain socket connection (open socket link )

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() ). It returns a file handle

Open PHP fsockopen function

PHP fsockopen requires the allow_url_fopen option in PHP.ini to be turned on.

<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><span class="tag-name">br</span><span> </span><span class="tag">/></span><span>n";   </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

The above is the specific method of using the PHP fsockopen function for your reference and study.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446176.htmlTechArticleThere is also a function starting with curl_, which can implement many functions. Do some research when you have time! The following is an introduction to fscokopen 1. PHP fsockopen function description: Open Internet or Unix d...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template