Home > Backend Development > PHP Tutorial > Usage example of PHP stream_context_create() function, createfile function_PHP tutorial

Usage example of PHP stream_context_create() function, createfile function_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:54:11
Original
1031 people have browsed it

Usage example of PHP stream_context_create() function, createfile function

stream_context_create() function is used to create context file options for opening files, used for fopen(), file_get_contents() Special processes such as timeout settings, proxy servers, request methods, and header information settings.

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

Using stream_context_create() to set the proxy server:
Copy code 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:
Copy code The code is as follows:
$opts = array(
'http'=>array(
'method'=>"GET",
'timeout'=>60,
)
);
$context = stream_context_create($opts);
$html =file_get_contents('http://www.bkjia.com', false, $context);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/998563.htmlTechArticleUsage example of PHP stream_context_create() function, createfile function stream_context_create() function is used to create context files for opening files Options for fopen(), file_get_content...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template