http
分機上(package名是pecl_http
)不提供http_get()
功能的最新版本。該功能已在版本2.0.0(版本1.7.6之後)中被刪除。您可以通過在終端運行以下命令看到:
git clone https://github.com/m6w6/ext-http.git
cd ext-http
git diff RELEASE_1_7_6 RELEASE_2_0_0
雖然沒有在changelog明確提到它,程序風格是完全面向對象的風格在第二個版本所取代。
documentation on PHP's official site已過時。 Extension的作者在his own site上託管了新版本。我不會責怪他,因爲PECL site上的文檔鏈接指向正確的位置。毫無疑問,他應該從php.net/manual
中刪除舊文檔,或者至少更新它。
執行HTTP GET請求的新方式意味着使用http\Client\Request
類:
$request = new http\Client\Request("GET",
"http://example.com",
["User-Agent"=>"MyAgent/0.1"]
);
$request->setOptions(["timeout" => 1]);
$client = new http\Client;
$client->enqueue($request)->send();
$response = $client->getResponse();
關於建立
你應該,因爲它是在推薦加載依賴http.so
前documentation:
; obligatory deps
extension = raphf.so
extension = propro.so
; if shared deps were enabled
extension = hash.so
extension = iconv.so
extension = json.so
; finally load pecl/http
extension = http.so
如果你還沒有,你必須在你的'php.ini'文件中啓用'; extension = php_http.dll'。只需刪除分號,然後重新啓動Apache服務器。 –