@@ -23,9 +23,13 @@ To install PHP Curl Class, simply:
23
23
24
24
$ composer require php-curl-class/php-curl-class
25
25
26
+ For latest commit version:
27
+
28
+ $ composer require php-curl-class/php-curl-class @dev
29
+
26
30
### Requirements
27
31
28
- PHP Curl Class works with PHP 5.3, 5.4, 5.5, 5.6, 7.0, and HHVM.
32
+ PHP Curl Class works with PHP 5.3, 5.4, 5.5, 5.6, 7.0, 7.1, and HHVM.
29
33
30
34
### Quick Start and Examples
31
35
@@ -37,57 +41,36 @@ require __DIR__ . '/vendor/autoload.php';
37
41
use \Curl\Curl;
38
42
39
43
$curl = new Curl();
40
- $curl->get('http ://www.example.com/');
44
+ $curl->get('https ://www.example.com/');
41
45
```
42
46
43
47
``` php
44
48
$curl = new Curl();
45
- $curl->get('http ://www.example.com/search', array(
49
+ $curl->get('https ://www.example.com/search', array(
46
50
'q' => 'keyword',
47
51
));
48
52
```
49
53
50
54
``` php
51
55
$curl = new Curl();
52
- $curl->post('http://www.example.com/login/', array(
53
- 'username' => 'myusername',
54
- 'password' => 'mypassword',
55
- ));
56
-
57
- // Perform a post-redirect-get request (POST data and follow 303 redirections using GET requests).
58
- $curl = new Curl();
59
- $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);¬
60
- $curl->post('http://www.example.com/login/', array(
56
+ $curl->post('https://www.example.com/login/', array(
61
57
'username' => 'myusername',
62
58
'password' => 'mypassword',
63
59
));
64
-
65
- // POST data and follow 303 redirections by POSTing data again.
66
- // Please note that 303 redirections should not be handled this way:
67
- // https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4
68
- $curl = new Curl();
69
- $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);¬
70
- $curl->post('http://www.example.com/login/', array(
71
- 'username' => 'myusername',
72
- 'password' => 'mypassword',
73
- ), false);
74
60
```
75
61
76
- A POST request performs by default a post-redirect-get (see above). Other request methods force an option which conflicts with the post-redirect-get behavior. Due to technical limitations of PHP engines <5.5.11 and HHVM, it is not possible to reset this option. It is therefore impossible to perform a post-redirect-get request using a php-curl-class Curl object that has already been used to perform other types of requests. Either use a new php-curl-class Curl object or upgrade your PHP engine.
77
-
78
62
``` php
79
63
$curl = new Curl();
80
64
$curl->setBasicAuthentication('username', 'password');
81
- $curl->setUserAgent('');
65
+ $curl->setUserAgent('MyUserAgent/0.0.1 (+https://www.example.com/bot.html) ');
82
66
$curl->setReferrer('');
83
67
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
84
68
$curl->setCookie('key', 'value');
85
- $curl->get('http ://www.example.com/');
69
+ $curl->get('https ://www.example.com/');
86
70
87
71
if ($curl->error) {
88
72
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
89
- }
90
- else {
73
+ } else {
91
74
echo $curl->response;
92
75
}
93
76
@@ -97,35 +80,35 @@ var_dump($curl->responseHeaders);
97
80
98
81
``` php
99
82
$curl = new Curl();
100
- $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false );
101
- $curl->get('https://encrypted .example.com/');
83
+ $curl->setOpt(CURLOPT_FOLLOWLOCATION, true );
84
+ $curl->get('https://shortn .example.com/bHbVsP ');
102
85
```
103
86
104
87
``` php
105
88
$curl = new Curl();
106
- $curl->put('http ://api.example.com/user/', array(
89
+ $curl->put('https ://api.example.com/user/', array(
107
90
'first_name' => 'Zach',
108
91
'last_name' => 'Borboa',
109
92
));
110
93
```
111
94
112
95
``` php
113
96
$curl = new Curl();
114
- $curl->patch('http ://api.example.com/profile/', array(
97
+ $curl->patch('https ://api.example.com/profile/', array(
115
98
'image' => '@path/to/file.jpg',
116
99
));
117
100
```
118
101
119
102
``` php
120
103
$curl = new Curl();
121
- $curl->patch('http ://api.example.com/profile/', array(
104
+ $curl->patch('https ://api.example.com/profile/', array(
122
105
'image' => new CURLFile('path/to/file.jpg'),
123
106
));
124
107
```
125
108
126
109
``` php
127
110
$curl = new Curl();
128
- $curl->delete('http ://api.example.com/user/', array(
111
+ $curl->delete('https ://api.example.com/user/', array(
129
112
'id' => '1234',
130
113
));
131
114
```
@@ -165,7 +148,8 @@ $multi_curl = new MultiCurl();
165
148
166
149
$multi_curl->success(function($instance) {
167
150
echo 'call to "' . $instance->url . '" was successful.' . "\n";
168
- echo 'response: ' . $instance->response . "\n";
151
+ echo 'response:' . "\n";
152
+ var_dump($instance->response);
169
153
});
170
154
$multi_curl->error(function($instance) {
171
155
echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
@@ -189,37 +173,42 @@ $multi_curl->addGet('https://www.bing.com/search', array(
189
173
$multi_curl->start(); // Blocks until all items in the queue have been processed.
190
174
```
191
175
176
+ More examples are available under [ /examples] ( https://github.com/php-curl-class/php-curl-class/tree/master/examples ) .
177
+
192
178
### Available Methods
193
179
``` php
194
180
Curl::__construct($base_url = null)
195
181
Curl::__destruct()
182
+ Curl::__get($name)
196
183
Curl::beforeSend($callback)
197
184
Curl::buildPostData($data)
198
185
Curl::call()
199
186
Curl::close()
200
187
Curl::complete($callback)
201
188
Curl::delete($url, $query_parameters = array(), $data = array())
202
189
Curl::download($url, $mixed_filename)
203
- Curl::downloadComplete($fh)
204
190
Curl::error($callback)
205
191
Curl::exec($ch = null)
206
192
Curl::get($url, $data = array())
207
193
Curl::getCookie($key)
194
+ Curl::getInfo($opt)
208
195
Curl::getOpt($option)
209
196
Curl::getResponseCookie($key)
210
- Curl::getResponseCookies()
211
197
Curl::head($url, $data = array())
212
198
Curl::headerCallback($ch, $header)
213
199
Curl::options($url, $data = array())
214
200
Curl::patch($url, $data = array())
215
- Curl::post($url, $data = array(), $post_redirect_get = false)
201
+ Curl::post($url, $data = array(), $follow_303_with_post = false)
216
202
Curl::progress($callback)
217
203
Curl::put($url, $data = array())
204
+ Curl::search($url, $data = array())
218
205
Curl::setBasicAuthentication($username, $password = '')
219
206
Curl::setConnectTimeout($seconds)
220
207
Curl::setCookie($key, $value)
221
208
Curl::setCookieFile($cookie_file)
222
209
Curl::setCookieJar($cookie_jar)
210
+ Curl::setCookieString($string)
211
+ Curl::setDefaultDecoder($decoder = 'json')
223
212
Curl::setDefaultJsonDecoder()
224
213
Curl::setDefaultTimeout()
225
214
Curl::setDefaultUserAgent()
@@ -228,6 +217,7 @@ Curl::setDigestAuthentication($username, $password = '')
228
217
Curl::setHeader($key, $value)
229
218
Curl::setJsonDecoder($function)
230
219
Curl::setOpt($option, $value)
220
+ Curl::setOpts($options)
231
221
Curl::setPort($port)
232
222
Curl::setReferer($referer)
233
223
Curl::setReferrer($referrer)
@@ -237,8 +227,8 @@ Curl::setUserAgent($user_agent)
237
227
Curl::setXmlDecoder($function)
238
228
Curl::success($callback)
239
229
Curl::unsetHeader($key)
240
- Curl::verbose($on = true, $output= STDERR)
241
- Curl::http_build_multi_query($data , $key = null )
230
+ Curl::verbose($on = true, $output = STDERR)
231
+ Curl::array_flatten_multidim($array , $prefix = false )
242
232
Curl::is_array_assoc($array)
243
233
Curl::is_array_multidim($array)
244
234
MultiCurl::__construct($base_url = null)
@@ -249,21 +239,27 @@ MultiCurl::addGet($url, $data = array())
249
239
MultiCurl::addHead($url, $data = array())
250
240
MultiCurl::addOptions($url, $data = array())
251
241
MultiCurl::addPatch($url, $data = array())
252
- MultiCurl::addPost($url, $data = array(), $post_redirect_get = false)
242
+ MultiCurl::addPost($url, $data = array(), $follow_303_with_post = false)
253
243
MultiCurl::addPut($url, $data = array())
244
+ MultiCurl::addSearch($url, $data = array())
254
245
MultiCurl::beforeSend($callback)
255
246
MultiCurl::close()
256
247
MultiCurl::complete($callback)
257
248
MultiCurl::error($callback)
258
249
MultiCurl::getOpt($option)
259
250
MultiCurl::setBasicAuthentication($username, $password = '')
251
+ MultiCurl::setConcurrency($concurrency)
252
+ MultiCurl::setConnectTimeout($seconds)
260
253
MultiCurl::setCookie($key, $value)
261
254
MultiCurl::setCookieFile($cookie_file)
262
255
MultiCurl::setCookieJar($cookie_jar)
256
+ MultiCurl::setCookieString($string)
263
257
MultiCurl::setDigestAuthentication($username, $password = '')
264
258
MultiCurl::setHeader($key, $value)
265
259
MultiCurl::setJsonDecoder($function)
266
260
MultiCurl::setOpt($option, $value)
261
+ MultiCurl::setOpts($options)
262
+ MultiCurl::setPort($port)
267
263
MultiCurl::setReferer($referer)
268
264
MultiCurl::setReferrer($referrer)
269
265
MultiCurl::setTimeout($seconds)
@@ -273,7 +269,7 @@ MultiCurl::setXmlDecoder($function)
273
269
MultiCurl::start()
274
270
MultiCurl::success($callback)
275
271
MultiCurl::unsetHeader($key)
276
- MultiCurl::verbose($on = true)
272
+ MultiCurl::verbose($on = true, $output = STDERR )
277
273
```
278
274
279
275
### Contribute
0 commit comments