Usage example of PHP stream_context_create() function_PHP tutorial

WBOY
Release: 2016-07-13 09:53:39
Original
838 people have browsed it

Examples of using the PHP stream_context_create() function

This article mainly introduces examples of using the PHP stream_context_create() function. The stream_context_create() function is used to create the context of an open file. File options are used for timeout settings, proxy servers, request methods, and header information settings for fopen(), file_get_contents() and other processes. Friends in need can refer to the following

The stream_context_create() function is used to create context options for opening files, and is a special process used for timeout settings, proxy servers, request methods, and header information settings for fopen(), file_get_contents() and other processes.

For example, in the last PHP tutorial, the gd library implements downloading of all pictures on the web page, line 10:

Use stream_context_create() to set the proxy server:

The code is as follows:

//Set proxy server

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

$context = stream_context_create($opts);

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

Use stream_context_create() to set the timeout:

The code is as follows:

 $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.htmlTechArticleUsage examples of the PHP stream_context_create() function This article mainly introduces the usage examples of the PHP stream_context_create() function, stream_context_create The () function is used to create open files...
Related labels:
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