详解PHP fsockopen的使用方法

开发 后端
PHP fsockopen函数对于我们刚刚接触PHP语言的人来说,还是不太了解其具体功能。希望通过本文介绍的内容能对大家起到一定的帮助。

PHP fsockopen是一个功能比较强大的函数。我们在这篇文章中将会对这个函数做一个具体的介绍,希望对大家有所帮助。记得以前的B2C网站就是通过这个函数实现前台和订单处理系统的交互。#t#

还有一个以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.1\r\n";   
  6. $out ."Host: www.example.com\r\n";   
  7. $out ."Connection: Close\r\n\r\n";   
  8.  
  9. fwrite($fp, $out);   
  10. while (!feof($fp)) {   
  11. echo fgets($fp, 128);   
  12. }   
  13. fclose($fp);   
  14. }  

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

责任编辑:曹凯 来源: 网易博客
相关推荐

2009-11-30 17:43:54

PHP split()

2011-06-16 11:01:56

PHP继承

2009-12-07 16:52:59

PHP函数getima

2009-12-02 18:51:12

PHP分页类

2009-12-28 13:28:03

WPF视频

2009-11-17 17:38:37

PHP Session

2009-12-02 15:02:09

PHP simplex

2011-07-12 17:11:13

PHPSHELL

2009-11-24 15:50:09

PHP上传类uploa

2009-08-25 16:54:28

C# RichText

2009-12-01 17:00:49

PHP变量

2009-12-02 14:50:25

PHP接口类inter

2009-11-25 10:02:27

PHP会话Sessio

2009-11-26 19:05:04

PHP函数explod

2009-11-26 15:23:24

PHP函数ereg()

2009-11-24 19:25:32

PHP关联数组

2010-01-28 17:07:03

Android Gal

2010-10-09 10:30:03

JS event

2010-06-03 17:38:03

Hadoop命令

2010-06-01 19:55:30

SVN使用
点赞
收藏

51CTO技术栈公众号