piedweb / curl
curl OOP Wrapper
Installs: 31 447
Dependents: 7
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=8.3
- kelvinzer0/curl-impersonate-php: ^3.2
- thecodingmachine/safe: ^2.1
- dev-main
- 0.1.804
- 0.1.803
- 0.1.802
- 0.1.801
- 0.1.800
- 0.1.799
- 0.1.798
- 0.1.797
- 0.1.796
- 0.1.795
- 0.1.794
- 0.1.793
- 0.1.792
- 0.1.791
- 0.1.790
- 0.1.789
- 0.1.788
- 0.1.787
- 0.1.786
- 0.1.785
- 0.1.784
- 0.1.783
- 0.1.782
- 0.1.781
- 0.1.78
- 0.1.77
- 0.1.76
- 0.1.75
- 0.1.74
- 0.1.73
- 0.1.72
- 0.1.71
- 0.1.70
- 0.1.69
- 0.1.68
- 0.1.67
- 0.1.66
- 0.1.65
- 0.1.64
- 0.1.63
- 0.1.62
- 0.1.61
- 0.1.60
- 0.1.59
- 0.1.58
- 0.1.57
- 0.1.56
- 0.1.55
- 0.1.54
- 0.1.53
- 0.1.52
- 0.1.51
- 0.1.50
- 0.1.49
- 0.1.48
- 0.1.47
- 0.1.46
- 0.1.45
- 0.1.44
- 0.1.43
- 0.1.42
- 0.1.41
- 0.1.40
- 0.1.35
- 0.1.34
- 0.1.33
- 0.1.32
- 0.1.30
- 0.1.24
- 0.1.23
- 0.1.22
- 0.1.21
- 0.1.20
- 0.1.17
- 0.1.16
- 0.1.15
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.08
- 0.1.07
- 0.1.06
- 0.1.02
- 0.1.01
- v0.0.18
- 0.0.17
- 0.0.16
- 0.0.15
- 0.0.14
- 0.0.13
- 0.0.12
- 0.0.11
- 0.0.10
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-dependabot/add-v2-config-file
This package is auto-updated.
Last update: 2024-11-20 22:03:21 UTC
README
Simple PHP Curl OOP wrapper for efficient request.
For a more complex or abstracted curl wrapper, use Guzzle.
Install
Via Packagist
$ composer require piedweb/curl
Usage
Quick Example :
$url = 'https://piedweb.com'; $request = new \PiedWeb\Curl\ExtendedClient($url); $request ->setDefaultSpeedOptions(true) ->setDownloadOnlyIf('PiedWeb\Curl\Helper::checkContentType') // 'PiedWeb\Curl\Helper::checkStatusCode' ->setDesktopUserAgent() ; $result = $request->request(); if ($result instanceof \PiedWeb\Curl\Response) { $content = $this->getContent(); }
Static Wrapper Methods :
use PiedWeb\Curl\StaticClient as Client; Client::request($url); // @return ?string Client::get(); // @return PiedWeb\Curl\ExtendedClient Client::reset()
All Other Methods :
$r = new PiedWeb\Curl\ExtendedClient(?string $url); $r ->setOpt(CURLOPT_*, mixed 'value') // Preselect Options to avoid eternity wait ->setDefaultGetOptions($connectTimeOut = 5, $timeOut = 10, $dnsCacheTimeOut = 600, $followLocation = true, $maxRedirs = 5) ->setDefaultSpeedOptions() // no header except if setted, 1 redir max, no ssl check ->setNoFollowRedirection() ->setReturnOnlyHeader() ->setCookie(string $cookie) ->setReferer(string $url) ->fakeBrowserHeader(bool $doIt = true) ->setUserAgent(string $ua) ->setDesktopUserAgent() ->setMobileUserAgent() ->setLessJsUserAgent() ->getUserAgent() // @return string ->setDownloadOnlyIf(callable $func) // @param $ContentType can be a String or an Array ->setMaximumResponseSize(int $tooBig = 200000) // @defaut 2Mo ->setDownloadOnly($range = '0-500') ->setPost(array $post) ->setEncodingGzip() ->setProxy(string '[scheme]proxy-host:port[:username:passwrd]') // Scheme, username and passwrd are facultatives. Default Scheme is http:// ->setTarget($url) ->getTarget() $r->request(); // @return true if request succeed else false (see getError) $response = $r->getResponse(); // @return PiedWeb\Curl\Response or int corresponding to the curl error $response->getUrl(); // @return string $response->getContentType(); // @return string $response->getContent(); // @return string $response->getHeaders($returnArray = true); // @return array Response Header (or in a string if $returnArray is set to false) $response->getCookies(); // @return string $response->getUrl(); // @return string $response->getError(); // Equivalent to curl function curl_errno $response->getErrorMessage(); // .. curl_error use PiedWeb\Curl\ResponseFromCache; $response = new ResponseFromCache( // same methods than Response except getRequest return null string $filePathOrContent, ?string $url = null, array $info = [], $headers = PHP_EOL.PHP_EOL );
Contributing
Please see contributing
Credits
License
The MIT License (MIT). Please see License File for more information.