Heim  >  Artikel  >  Backend-Entwicklung  >  PHP stream_context_create()函数的使用示例_PHP教程

PHP stream_context_create()函数的使用示例_PHP教程

WBOY
WBOYOriginal
2016-07-13 09:53:39788Durchsuche

PHP stream_context_create()函数的使用示例

   这篇文章主要介绍了PHP stream_context_create()函数的使用示例,stream_context_create()函数是用来 创建打开文件的上下文件选项,用于fopen(),file_get_contents()等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程,需要的朋友可以参考下

  stream_context_create()函数是用来 创建打开文件的上下文件选项 ,用于fopen(),file_get_contents()等过程的超时设置、代理服务器、请求方式、头信息设置的特殊过程。

  比如说,上篇php教程中gd库实现下载网页所有图片中,第10行:

  利用了stream_context_create()设置代理服务器:

   代码如下:

  //设置代理服务器

  $opts = array('http'=>array('request_fulluri'=>true));

  $context = stream_context_create($opts);

  $content = file_get_contents($url,false,$context);

  利用了stream_context_create()设置超时时间:

   代码如下:

  $opts = array(

  'http'=>array(

  'method'=>"GET",

  'timeout'=>60,

  )

  );

  $context = stream_context_create($opts);

  $html =file_get_contents('http://www.jb51.net', false, $context);

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1000116.htmlTechArticlePHP stream_context_create()函数的使用示例 这篇文章主要介绍了PHP stream_context_create()函数的使用示例,stream_context_create()函数是用来 创建打开文件...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn