Download the PHP package masterklavi/phprequest without Composer
On this page you can find all versions of the php package masterklavi/phprequest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phprequest
PHP Request
It includes some functions to easy requesting and parsing data.
Examples
Requirements
- PHP version 5.4.0 or higher
- PHP extension
ext-curl
enabled
Installation
Using Composer
Get the package:
Include vendor/autoload.php
:
Manual Installation
Clone git repository:
or download the package at https://github.com/masterklavi/phprequest/archive/master.zip
Include autoload.php
:
Methods
Request::request
Requests the given URL.
Syntax
Parameters
$url
– URL address
$options
– Array of request options
Return Values
Returns a response (body) as string
by default.
Returns a mixed
value when the filter
option's set.
Returns false
on failure.
Request::get
Alias of Request::request()
Request::post
Equivalent of
Request::multi
Requests the given URLs (parallel requests using curl multi).
Syntax
Parameters
$url
– Array of URL address strings or arrays of URL addresses and their options (e.g. [ 'http://a.ru', ['http://b.ru', ['filter' => 'json']] ]
)
$options
– Array of request options
Return Values
Returns an array
of results for the given urls.
Result may contain:
- a response (body) as
string
by default - a
mixed
value when thefilter
option's set false
on failure
Request::multiGet
Alias of Request::multi()
Request::multiPost
Equivalent of
Request Options
List of curl options:
Name | Type | Default | Description |
---|---|---|---|
method | string | GET |
The method of the HTTP request (GET, POST, HEAD, PUT, DELETE) (see CURLOPT_POST, CURLOPT_CUSTOMREQUEST) |
data | string, array | Querystring for GET, HEAD and DELETE requests, or request body for others (see CURLOPT_POSTFIELDS) | |
follow | boolean | false |
Follow HTTP redirections (see CURLOPT_FOLLOWLOCATION) |
encoding | string | The contents of the "Accept-Encoding: " header (see CURLOPT_ENCODING) | |
timeout | integer | 300 |
The timeout of one request (see CURLOPT_TIMEOUT) |
session | string | Path to cookie-based session file (enables session between different calls) (see CURLOPT_COOKIEJAR) | |
cookie | string | The contents of the "Cookie: " header (see CURLOPT_COOKIE) | |
headers | array | An array of HTTP headers (see CURLOPT_HTTPHEADER) | |
referer | string | The contents of the "Referer: " header (see CURLOPT_REFERER) | |
useragent | string | The contents of the "User-Agent: " header (see CURLOPT_USERAGENT) | |
proxy | string | Proxy string like IP:PORT or username:password@IP:PORT (see CURLOPT_PROXY, CURLOPT_PROXYUSERPWD) | |
interface | string | Used interface (IP or host) (see CURLOPT_INTERFACE) | |
curl | array | An array of custom curl options |
List of special options:
Name | Type | Default | Description |
---|---|---|---|
allowed_codes | array | [200] |
Allowed HTTP codes |
allow_empty | boolean | false |
Allows empty body of the HTTP response |
filter | string, callable | Filters body (usually to reduce memory usage). See Available filters | |
charset | string | The charset of requested content (the result will contain 'utf8') | |
attempts | integer | 5 |
Number of request attempts |
concurrency | integer | 10 |
Concurrency of requests in Request::multi() |
Filters
Plain filters:
json
- interprets the body as json and returns an objectjson_assoc
- interprets the body as json and returns an associative arrayxml
- interprets the body as xml and returns SimpleXML objectsplain
- returns full response (with headers) as plain textheaders
- returns a set of the headersheaders_body
- returns a set of the headers and the body as plain text
Complex filters:
-
cut
- cuts out a new substring usingbegin
andend
substrings (tags)
Syntax:where
$options
is key-value array that may contains:'begin' => 'some string'
- substring as beginning of the cut'end' => 'some string'
- substring as ending of the cut'case_sensivity' => true
- use begin and end as case sensivity substrings'mbstring' => true
- use mb_* functions on cutting
-
regex
- returns an array of the results matched the regular expression (usespreg_match
)
Syntax:Returns
null
if thepattern
doesn't match the body, orfalse
if an error occured regex_one
- returns the first matched text (usespreg_match
)regex_all
- returns an array of arrays of the results of search used the regular expression (usespreg_match_all
)regex_set
- returns an array of arrays of the results of search used the regular expression (usespreg_match_all
with the set order)regex_col
- returns an array of the results of the first values matched the regular expression (usespreg_match_all
)
All versions of phprequest with dependencies
ext-curl Version *