fyre/curl
Composer 安装命令:
composer require fyre/curl
包简介
A cURL library.
README 文档
README
FyreCURL is a free, open-source cURL request library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/curl
In PHP:
use Fyre\CURL\Curl;
Methods
Delete
Perform a DELETE request.
$urlis a string representing the URL.$optionsis an array containing the request options.headersis an array containing additional headers to set, and will default to [].userAgentis a string representing the user agent, and will default to null.protocolVersionis a string representing the HTTP protocol version, and will default to "1.1".usernameis a string representing the HTTP authentication username, and will default to null.passwordis a string representing the HTTP authentication password, and will default to null.authis a string representing the authentication method, and will default to "basic".sslCertis a string representing the file path of the SSL certificate, and will default to null.sslPasswordis a string representing the SSL certificate password, and will default to null.sslKeyis a string representing the file path of the SSL key, and will default to null.cookieis a string representing the file path of the cookie file, and will default to null.redirectis a boolean indicating whether to allow redirects, and will default to true.redirectOptionsis an array containing redirect options.maxis a number representing the maximum number of redirects, and will default to 5.strictis a boolean indicating whether to only follow 301, 302 and 303 redirects, and will default to true.protocolsis an integer bitmask representing the protocols to allow redirects for, and will default to CURLPROTO_HTTP | CURLPROTO_HTTPS.
verifyis a boolean indicating whether to verify the peer SSL certificate, and will default to true.delayis a number representing the number of seconds to wait before executing the request, and will default to 0.timeoutis a number representing the maximum number of seconds for cURL to initialize, and will default to 0.connectTimeoutis a number representing the maximum number of seconds trying to connect, and will default to 150.
$response = Curl::delete($url, $options);
This method returns a new CurlResponse.
Get
Perform a GET request.
$urlis a string representing the URL.$optionsis an array containing the request options.headersis an array containing additional headers to set, and will default to [].datais an array containing additional data to send with the request, and will default to null.userAgentis a string representing the user agent, and will default to null.protocolVersionis a string representing the HTTP protocol version, and will default to "1.1".usernameis a string representing the HTTP authentication username, and will default to null.passwordis a string representing the HTTP authentication password, and will default to null.authis a string representing the authentication method, and will default to "basic".sslCertis a string representing the file path of the SSL certificate, and will default to null.sslPasswordis a string representing the SSL certificate password, and will default to null.sslKeyis a string representing the file path of the SSL key, and will default to null.cookieis a string representing the file path of the cookie file, and will default to null.redirectis a boolean indicating whether to allow redirects, and will default to true.redirectOptionsis an array containing redirect options.maxis a number representing the maximum number of redirects, and will default to 5.strictis a boolean indicating whether to only follow 301, 302 and 303 redirects, and will default to true.protocolsis an integer bitmask representing the protocols to allow redirects for, and will default to CURLPROTO_HTTP | CURLPROTO_HTTPS.
verifyis a boolean indicating whether to verify the peer SSL certificate, and will default to true.delayis a number representing the number of seconds to wait before executing the request, and will default to 0.timeoutis a number representing the maximum number of seconds for cURL to initialize, and will default to 0.connectTimeoutis a number representing the maximum number of seconds trying to connect, and will default to 150.
$response = Curl::get($url, $options);
This method returns a new CurlResponse.
Head
Perform a HEAD request.
$urlis a string representing the URL.$optionsis an array containing the request options.headersis an array containing additional headers to set, and will default to [].userAgentis a string representing the user agent, and will default to null.protocolVersionis a string representing the HTTP protocol version, and will default to "1.1".usernameis a string representing the HTTP authentication username, and will default to null.passwordis a string representing the HTTP authentication password, and will default to null.authis a string representing the authentication method, and will default to "basic".sslCertis a string representing the file path of the SSL certificate, and will default to null.sslPasswordis a string representing the SSL certificate password, and will default to null.sslKeyis a string representing the file path of the SSL key, and will default to null.cookieis a string representing the file path of the cookie file, and will default to null.redirectis a boolean indicating whether to allow redirects, and will default to true.redirectOptionsis an array containing redirect options.maxis a number representing the maximum number of redirects, and will default to 5.strictis a boolean indicating whether to only follow 301, 302 and 303 redirects, and will default to true.protocolsis an integer bitmask representing the protocols to allow redirects for, and will default to CURLPROTO_HTTP | CURLPROTO_HTTPS.
verifyis a boolean indicating whether to verify the peer SSL certificate, and will default to true.delayis a number representing the number of seconds to wait before executing the request, and will default to 0.timeoutis a number representing the maximum number of seconds for cURL to initialize, and will default to 0.connectTimeoutis a number representing the maximum number of seconds trying to connect, and will default to 150.
$response = Curl::head($url, $options);
This method returns a new CurlResponse.
Options
Perform an OPTIONS request.
$urlis a string representing the URL.$optionsis an array containing the request options.headersis an array containing additional headers to set, and will default to [].userAgentis a string representing the user agent, and will default to null.protocolVersionis a string representing the HTTP protocol version, and will default to "1.1".usernameis a string representing the HTTP authentication username, and will default to null.passwordis a string representing the HTTP authentication password, and will default to null.authis a string representing the authentication method, and will default to "basic".sslCertis a string representing the file path of the SSL certificate, and will default to null.sslPasswordis a string representing the SSL certificate password, and will default to null.sslKeyis a string representing the file path of the SSL key, and will default to null.cookieis a string representing the file path of the cookie file, and will default to null.redirectis a boolean indicating whether to allow redirects, and will default to true.redirectOptionsis an array containing redirect options.maxis a number representing the maximum number of redirects, and will default to 5.strictis a boolean indicating whether to only follow 301, 302 and 303 redirects, and will default to true.protocolsis an integer bitmask representing the protocols to allow redirects for, and will default to CURLPROTO_HTTP | CURLPROTO_HTTPS.
verifyis a boolean indicating whether to verify the peer SSL certificate, and will default to true.delayis a number representing the number of seconds to wait before executing the request, and will default to 0.timeoutis a number representing the maximum number of seconds for cURL to initialize, and will default to 0.connectTimeoutis a number representing the maximum number of seconds trying to connect, and will default to 150.
$response = Curl::options($url, $options);
This method returns a new CurlResponse.
Patch
Perform a PATCH request.
$urlis a string representing the URL.$datais an array containing the data.$optionsis an array containing the request options.headersis an array containing additional headers to set, and will default to [].dataTypeis a string representing the type of data to send with the request, and will default to "json".userAgentis a string representing the user agent, and will default to null.protocolVersionis a string representing the HTTP protocol version, and will default to "1.1".usernameis a string representing the HTTP authentication username, and will default to null.passwordis a string representing the HTTP authentication password, and will default to null.authis a string representing the authentication method, and will default to "basic".sslCertis a string representing the file path of the SSL certificate, and will default to null.sslPasswordis a string representing the SSL certificate password, and will default to null.sslKeyis a string representing the file path of the SSL key, and will default to null.cookieis a string representing the file path of the cookie file, and will default to null.redirectis a boolean indicating whether to allow redirects, and will default to true.redirectOptionsis an array containing redirect options.maxis a number representing the maximum number of redirects, and will default to 5.strictis a boolean indicating whether to only follow 301, 302 and 303 redirects, and will default to true.protocolsis an integer bitmask representing the protocols to allow redirects for, and will default to CURLPROTO_HTTP | CURLPROTO_HTTPS.
verifyis a boolean indicating whether to verify the peer SSL certificate, and will default to true.delayis a number representing the number of seconds to wait before executing the request, and will default to 0.timeoutis a number representing the maximum number of seconds for cURL to initialize, and will default to 0.connectTimeoutis a number representing the maximum number of seconds trying to connect, and will default to 150.
$response = Curl::patch($url, $data, $options);
This method returns a new CurlResponse.
Post
Perform a POST request.
$urlis a string representing the URL.$datais an array containing the data.$optionsis an array containing the request options.headersis an array containing additional headers to set, and will default to [].dataTypeis a string representing the type of data to send with the request, and will default to null.userAgentis a string representing the user agent, and will default to null.protocolVersionis a string representing the HTTP protocol version, and will default to "1.1".usernameis a string representing the HTTP authentication username, and will default to null.passwordis a string representing the HTTP authentication password, and will default to null.authis a string representing the authentication method, and will default to "basic".sslCertis a string representing the file path of the SSL certificate, and will default to null.sslPasswordis a string representing the SSL certificate password, and will default to null.sslKeyis a string representing the file path of the SSL key, and will default to null.cookieis a string representing the file path of the cookie file, and will default to null.redirectis a boolean indicating whether to allow redirects, and will default to true.redirectOptionsis an array containing redirect options.maxis a number representing the maximum number of redirects, and will default to 5.strictis a boolean indicating whether to only follow 301, 302 and 303 redirects, and will default to true.protocolsis an integer bitmask representing the protocols to allow redirects for, and will default to CURLPROTO_HTTP | CURLPROTO_HTTPS.
verifyis a boolean indicating whether to verify the peer SSL certificate, and will default to true.delayis a number representing the number of seconds to wait before executing the request, and will default to 0.timeoutis a number representing the maximum number of seconds for cURL to initialize, and will default to 0.connectTimeoutis a number representing the maximum number of seconds trying to connect, and will default to 150.
$response = Curl::post($url, $data, $options);
This method returns a new CurlResponse.
Put
Perform a PUT request.
$urlis a string representing the URL.$datais an array containing the data.$optionsis an array containing the request options.headersis an array containing additional headers to set, and will default to [].dataTypeis a string representing the type of data to send with the request, and will default to "json".userAgentis a string representing the user agent, and will default to null.protocolVersionis a string representing the HTTP protocol version, and will default to "1.1".usernameis a string representing the HTTP authentication username, and will default to null.passwordis a string representing the HTTP authentication password, and will default to null.authis a string representing the authentication method, and will default to "basic".sslCertis a string representing the file path of the SSL certificate, and will default to null.sslPasswordis a string representing the SSL certificate password, and will default to null.sslKeyis a string representing the file path of the SSL key, and will default to null.cookieis a string representing the file path of the cookie file, and will default to null.redirectis a boolean indicating whether to allow redirects, and will default to true.redirectOptionsis an array containing redirect options.maxis a number representing the maximum number of redirects, and will default to 5.strictis a boolean indicating whether to only follow 301, 302 and 303 redirects, and will default to true.protocolsis an integer bitmask representing the protocols to allow redirects for, and will default to CURLPROTO_HTTP | CURLPROTO_HTTPS.
verifyis a boolean indicating whether to verify the peer SSL certificate, and will default to true.delayis a number representing the number of seconds to wait before executing the request, and will default to 0.timeoutis a number representing the maximum number of seconds for cURL to initialize, and will default to 0.connectTimeoutis a number representing the maximum number of seconds trying to connect, and will default to 150.
$response = Curl::put($url, $data, $options);
This method returns a new CurlResponse.
Curl Requests
This class extends the Request class.
use Fyre\CURL\CurlRequest;
$uriis a Uri.$optionsis an array containing the request options.headersis an array containing additional headers to set, and will default to [].datais an array containing additional data to send with the request, and will default to null.dataTypeis a string representing the type of data to send with the request, and will default to "json".userAgentis a string representing the user agent, and will default to null.protocolVersionis a string representing the HTTP protocol version, and will default to "1.1".usernameis a string representing the HTTP authentication username, and will default to null.passwordis a string representing the HTTP authentication password, and will default to null.authis a string representing the authentication method, and will default to "basic".sslCertis a string representing the file path of the SSL certificate, and will default to null.sslPasswordis a string representing the SSL certificate password, and will default to null.sslKeyis a string representing the file path of the SSL key, and will default to null.cookieis a string representing the file path of the cookie file, and will default to null.redirectis a boolean indicating whether to allow redirects, and will default to true.redirectOptionsis an array containing redirect options.maxis a number representing the maximum number of redirects, and will default to 5.strictis a boolean indicating whether to only follow 301, 302 and 303 redirects, and will default to true.protocolsis an integer bitmask representing the protocols to allow redirects for, and will default to CURLPROTO_HTTP | CURLPROTO_HTTPS.
verifyis a boolean indicating whether to verify the peer SSL certificate, and will default to true.delayis a number representing the number of seconds to wait before executing the request, and will default to 0.timeoutis a number representing the maximum number of seconds for cURL to initialize, and will default to 0.connectTimeoutis a number representing the maximum number of seconds trying to connect, and will default to 150.
$request = new CurlRequest($url, $options);
Send
Send the request.
$response = $request->send();
This method returns a new CurlResponse.
Curl Responses
This class extends the Response class.
use Fyre\CURL\CurlResponse;
Get Json
Get the response body as decoded JSON.
$associativeis a boolean indicating whether to return JSON object as associative array, and will default to true.$depthis a number representing the maximum depth of nesting, and will default to 512.$flagsis a number representing additional flags to use for decoding, and will default to 0.
$data = $response->getJson($associative, $depth, $flags);
fyre/curl 适用场景与选型建议
fyre/curl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 06 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 fyre/curl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fyre/curl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-17