這篇文章主要介紹了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.49028c.com', false, $context);
新聞熱點
疑難解答