https://github.com/crazyfactory/php-curl
https://github.com/crazyfactory/php-curl
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/crazyfactory/php-curl
- Owner: crazyfactory
- Created: 2017-10-11T02:24:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-18T03:19:36.000Z (almost 8 years ago)
- Last Synced: 2025-02-16T15:31:16.732Z (over 1 year ago)
- Language: PHP
- Size: 13.7 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Curl
This wrapper around php's curl functions. PHP 5.3 compatible for sad reasons.
## Installation
Via composer
`composer require crazyfactory/curl`
## Usage
### Simple
Load a page
```php
$responseBody = (new Curl)->get('http://www.example.org');
```
### Sending fields
Pass in GET parameters as an array
```php
$responseBody = (new Curl)->get($url, [
'foo' => 'bar'
]);
```
Same for POST
```php
$responseBody = (new Curl)->post($url, [
'foo' => 'bar'
]);
```
For other methods, use `call()` directly.
### Curl options and info
`call()` accept an array of CURLOPT-constants and merges these with the defaults from `getDefaultOptions()`. `post()` and `get()` accept this array as 3rd parameter as well.
The last argument for all of these function is a reference to the returned curl-info for fancier things.
### Exceptions
`call()` will throw `CrazyFactory/Curl/Exception` when any error happens. It will also throw an Exception on 400+ status codes.
```php
try {
(new Curl)->get('http://httpbin.org/status/404');
}
catch (CrazyFactory/Curl/Exception $e) {
echo "Whoops we had a {$e->getHttpCode()}!";
}
```