ropendev/curl
Composer 安装命令:
composer require ropendev/curl
包简介
PHP POO cURL wrapper (PSR friendly) : light and simple.
README 文档
README
Make it easy to request a URL (or few) with PHP cURL
PHP POO cURL wrapper :
- PSR compliant,
- Easy install with composer,
- Intuitive and documented
- Light (~8 ko)
Simple cURL class wich transform procedural default cURL options in object. This class is giving some shortcuts like getCookie, setMobileUserAgent, setReferrer... for a more intuitive usage. And you can set cURL's options the old way with CurlRequest::setOpt($option, $value).
All the functions are documented in the class file.
Installation
Via Packagist :
composer require ropendev/curl
Usage
Single request
<?php use \rOpenDev\curl\CurlRequest; $request = new CurlRequest('http://www.example.org/'); $request->setDefaultGetOptions()->setReturnHeader()->setDestkopUserAgent()->setEncodingGzip(); $output = $curl->execute(); echo $output;
The above example will output the contet from example.org.
Single request with proxy, post and cookie
<?php use \rOpenDev\curl\CurlRequest; $request = new CurlRequest('http://www.bing.com/'); $request->setDefaultGetOptions()->setReturnHeader()->setDestkopUserAgent()->setEncodingGzip()->execute(); $r2 = new CurlRequest('http://www.bing.com/search?q=curl+request+php'); echo $r2->setDefaultGetOptions()->setReturnHeader()->setDestkopUserAgent()->setEncodingGzip()->setCookie($request->getCookie())->setProxy('domain:port:user:password')->execute();
Documentation
Are listed every public method.
<?php use rOpenDev\curl\CurlRequest; $r = new CurlRequest('scheme://host/path'); $r ->setOpt(CURLOPT_*, mixed 'value') // Preselect Options to avoid eternity wait ->setDefaultGetOptions($connectTimeOut = 5, $timeOut = 10, $dnsCacheTimeOut = 600, $followLocation = true, $maxRedirs = 5) ->setDefaultSpeedOptions() ->setReturnHeader() // If you want to get the header with getHeader() ->setCookie(string $cookie) ->setReferer(string $url) ->setUserAgent(string $ua) ->setDestkopUserAgent() ->setMobileUserAgent() ->setLessJsUserAgent() ->setPost(array $post) ->setEncodingGzip() ->setProxy(string '[scheme]proxy-host:port[:username:passwrd]') // Scheme, username and passwrd are facultatives. Default Scheme is http:// ->setReturnHeaderOnly() ->setUrl($url, $resetPreviousOptions) string $r->execute(); // Return contents from the url array $r->getHeader($arrayFormatted = true); // Return Response Header in an array (or in a string if $arrayFormatted is set to false) string $r->getCookies(); string $r->getEffectiveUrl(); $r->hasError|getError|getInfo(); // Equivalent to curl function curl_errno|curl_error|curl_getinfo();
License
MIT (see the LICENSE file for details)
Contributors
Before to submit a pull request, check test is still passing (phpunit).
- Original author : Robin (SEO Consultant in Marseille).
- Pied Web
- ...
ropendev/curl 适用场景与选型建议
ropendev/curl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.7k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2014 年 04 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「curl」 「http」 「request」 「spider」 「crawler」 「bot」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ropendev/curl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ropendev/curl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ropendev/curl 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
cURL and cURL based Soap-Client for PHP
repository php library
Simple cURL wrapper
HTTP request logger middleware for Laravel
A fluent PHP CURL wrapper
Adds request-parameter validation to the SLIM 3.x PHP framework
统计信息
- 总下载量: 6.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 37
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-04-29