php采用file_get_contents代替使用curl實例
本文實例講述了php采用file_get_contents代替使用curl的方法,分享給大家供大家參考。具體實現(xiàn)方法如下:
file_get_contents代替使用curl其實不多見了,但有時你碰到服務器不支持curl時我們可以使用file_get_contents代替使用curl,下面看個例子。
當用盡一切辦法發(fā)現(xiàn) 服務器真的無法使用curl時?;蛘遚url不支持https時。curl https 出現(xiàn)502時。你又不想重裝網(wǎng)站環(huán)境的時候,你就改用file_get_contents 代替吧。
curl 經(jīng)常使用的 curl get curl post
curl get 替代 直接用file_get_contents($url) 就可以了
curl post 替代如下:
$content = http_build_query($post);
$content_length = strlen($content);
$options = array(
'http' => array(
'method' => 'POST',
'header' =>"Content-type: application/x-www-form-urlencoded",
'content' => $post
)
);
return file_get_contents($url, false, stream_context_create($options));
}
希望本文所述對大家的php程序設計有所幫助。
- php基于curl重寫file_get_contents函數(shù)實例
- PHP CURL或file_get_contents獲取網(wǎng)頁標題的代碼及兩者效率的穩(wěn)定性問題
- php中file_get_contents與curl性能比較分析
- 深入file_get_contents與curl函數(shù)的詳解
- 探討file_get_contents與curl效率及穩(wěn)定性的分析
- 比file_get_contents穩(wěn)定的curl_get_contents分享
- php中使用Curl、socket、file_get_contents三種方法POST提交數(shù)據(jù)
- PHP curl 或 file_get_contents 獲取需要授權頁面的方法
相關文章
慎用preg_replace危險的/e修飾符(一句話后門常用)
要確保 replacement 構成一個合法的 PHP 代碼字符串,否則 PHP 會在報告在包含 preg_replace() 的行中出現(xiàn)語法解析錯誤2013-06-06PHP的array_diff()函數(shù)在處理大數(shù)組時的效率問題
PHP 5.2.6 以上版本的 array_diff() 函數(shù)在處理大數(shù)組時,需要花費超長時間,這個 bug 已經(jīng)被官方確認;在這個問題被修復之前或者在我們不能控制 PHP 版本的時候,可以使用本文提供的方法2011-11-11