首页 > php框架 > 详解PHP fsockopen的使用方法

详解PHP fsockopen的使用方法

还有一个以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 选项开启。
 

  1. $fp = fsockopen("www.example.com",
     80, $errno, $errstr, 30);   
  2. if (!$fp) {   
  3. echo "$errstr ($errno)<br />n";   
  4. } else {   
  5. $out = "GET / HTTP/1.1rn";   
  6. $out ."Host: www.example.comrn";   
  7. $out ."Connection: Closernrn";   
  8.  
  9. fwrite($fp, $out);   
  10. while (!feof($fp)) {   
  11. echo fgets($fp, 128);   
  12. }   
  13. fclose($fp);   
  14. }  

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


文章地址:http://www.phprm.com/frame/php1003793.html

转载随意^^请带上本文地址!

标签:none

发表留言