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

WBOY
WBOYOriginal
2016-07-13 09:54:111001browse

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...
Statement:
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