這篇文章主要介紹了PHP stream_context_create()函數(shù)的使用示例,stream_context_create()函數(shù)是用來 創(chuàng)建打開文件的上下文件選項,用于fopen(),file_get_contents()等過程的超時設(shè)置、代理服務(wù)器、請求方式、頭信息設(shè)置的特殊過程,需要的朋友可以參考下
stream_context_create()函數(shù)是用來 創(chuàng)建打開文件的上下文件選項 ,用于fopen(),file_get_contents()等過程的超時設(shè)置、代理服務(wù)器、請求方式、頭信息設(shè)置的特殊過程。
比如說,上篇php教程中g(shù)d庫實現(xiàn)下載網(wǎng)頁所有圖片中,第10行:
利用了stream_context_create()設(shè)置代理服務(wù)器:
- //設(shè)置代理服務(wù)器
- $opts = array('http'=>array('request_fulluri'=>true));
- $context = stream_context_create($opts);
- $content = file_get_contents($url,false,$context);
利用了stream_context_create()設(shè)置超時時間:
- $opts = array(
- 'http'=>array(
- 'method'=>"GET",
- 'timeout'=>60,
- )
- );
- $context = stream_context_create($opts);
- $html =file_get_contents('http://www.survivalescaperooms.com', false, $context);
新聞熱點
疑難解答