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中分号;
是注释。