windows環境。php
官網下載安裝。html
將php目錄放入環境變量PATH中,在CMD中能夠執行php命令。json
去官網下載安裝包安裝,中間有一步是要選PHP執行程序。 選擇PHP目錄下的php.exe
就好了。windows
編寫test.php,composer
start <?php echo 'hello world!';
運行:curl
$ php test.php start hello world!
編寫composer.json:ui
{ "require": { "guzzlehttp/guzzle": "~6.0" } }
運行 composer.bat install
。url
如今目錄結構以下:code
修改test.php:htm
<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; $client = new Client([ 'timeout' => 2.0, ]); $response = $client->get('http://www.baidu.com'); echo $response->getBody()->getContents();
運行:
$ php test.php // ... // ... www.baidu.com的首頁內容
若是去請求 https://www.baidu.com ,可能會報錯以下:
cURL error 60: SSL certificate problem: unable to get local issuer certificate (
http://stackoverflow.com/questions/29822686/curl-error-60-ssl-certificate-unable-to-get-local-issuer-certificate 和 https://easywechat.org/zh-cn/docs/troubleshooting.html 有討論。 https://curl.haxx.se/docs/sslcerts.html 是curl關於SSL的說明。
ca證書在這裏: https://curl.haxx.se/docs/caextract.html
推薦作法:
在 https://curl.haxx.se/docs/caextract.html 下載一個ca證書(文本文件)
然戶修改php.ini:
curl.cainfo = /path/to/downloaded/cacert.pem
或者修改
openssl.cafile= /path/to/downloaded/cacert.pem
注意,ini中分號;
是註釋。