Download the PHP package ares333/php-curl without Composer
On this page you can find all versions of the php package ares333/php-curl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ares333/php-curl
More information about ares333/php-curl
Files in ares333/php-curl
Informations about the package php-curl
中文文档
About
Implemented by using php-curl internal io event with high performance,high universality,high extensibility which especially suitable for massive tasks and complex logic cases.
Demand
PHP: >=5.3
Install
Features
- Extremely low cpu and memory consumption.
- All curl options are exposed directly which enables high universality and high extensibility.
- Api is very simple.
- Support process disruption and resume from last running state.
- Support dynamic tasks.
- Support transparent file cache.
- Support retry failed tasks automatically.
- Support global config,task config,callback config on same format and priority is from low to high.
- All configs can be changed on the fly and take effect immediately.
Work Flow
Curl::add() add tasks to task pool.Curl::start() start the event loop and block.Events(onSuccess,onFail,onInfo,onTask...) will be triggered and callbacks will be called on the fly.The loop finish when all tasks finished.
Tutorial
basic
file download
task callback
Task can be added in task callback. See more details in Curl::$onTask.
running info
Run in cli and will output with following format:
'onInfo' callback will receive all information.The default callback only show part of it.
transparent cache
Run the script second time and will output:
The result indicate that all tasks is using cache and there is no network activity.
dynamic tasks
Output is as below:
Finished url has '/' suffix because curl has processed the 3xx redirect automatically(Curl::$opt[CURLOPT_FOLLOWLOCATION]=true). Curl::onTask should be used to deal with massive tasks.
Curl (src/Curl.php Core functionality)
Max work parallels which can be change on the fly.
Max retry before onFail event is triggered.
Global CURLOPT_* which can be overwritten by task config.
Global cache config.Cache id is mapped from url.The config can be overwritten by task config and onSuccess callback return value with same format.
stack or queue.
Will be triggered when work parallels is less than Curl::$maxThread and task pool is empty.The callback parameter is current Curl instance.
Running state callback is triggered on IO events with max frequency 1/s.The parameters are as below:
- $info array with two keys 'all' and 'running'.Key 'running' contains response header(curl_getinfo()) for each running task.Key 'all' contains global information with keys as below:
- $info['all']['downloadSpeed'] Download speed.
- $info['all']['bodySize'] Body sized downloaded.
- $info['all']['headerSize'] Header size downloaded.
- $info['all']['activeNum'] Task has IO activity.
- $info['all']['queueNum'] Tasks waiting for onSuccess.
- $info['all']['finishNum'] Tasks has finished.
- $info['all']['cacheNum'] Cache hits.
- $info['all']['failNum'] Failed tasks number after retry.
- $info['all']['taskNum'] Task number in the task pool.
- $info['all']['taskRunningNum'] Running task number.
- $info['all']['taskPoolNum'] Task pool number.
- $info['all']['taskFailNum'] Retrying task number.
- Current Curl instance.
- Is last call or not.
Triggered on IO events.The callback parameter is current Curl instance.
Global callback for failed task which can be overwritten by task 'onTask'.The callback receive two parameters.
- array with keys as below:
- errorCode CURLE_* constants.
- errorMsg Error message.
- info Response header.
- curl Current Curl instance.
- $item['args'] value from Curl::add().
Add one task to the pool.
- $item
- $item['opt']=array() CURLOPT_* for current task.
- $item['args'] Parameters for callbacks.
- $item['cache']=array() Cache config for current task.
- $onSuccess Triggered on task finish.
- Callback has two Parameters:
- $result Array with keys as below:
- $result['info'] Response header.
- $result['curl'] Current Curl instance.
- $result['body'] Response body.Not exist in download task.
- $result['header'] Raw response header.Exists when CURLOPT_HEADER was enabled.
- $result['cacheFile'] Exists when cache is used.
- Value from $item['args']
- $result Array with keys as below:
- Values can be returned.Must be array if exist.Array keys is as below:
- cache Same format with Curl::$cache.This is the last chance to control caching.
- Callback has two Parameters:
- $onFail Overwrite Curl::$onFail。
- $ahead Add to high priority poll or not.
Return: current Curl instance.
Start the event loop and block.
Stop the event loop and return unprocessed tasks.
Parse http header and body from response.
Generate relative cache path.
Toolkit (src/Toolkit.php Necessary tools)
Default Curl instance is used if $curl is null.
The default instance will initialize Curl::$opt,Curl::onInfo,Curl::onFail. Curl::$opt initial values are as follows:
Default fail callback.See Curl::$onFail for details.
Default info callback.See Curl::onInfo for details.
The method can be triggered manually with a string parameter which will be added to output buffer.The purpose is to avoid interference of shell control characters.
Powerful html encoding transformer which can get current encoding automatically and replace html encoding value in \<head>\</head>. Parameters:
- $html Html string.
- $in Current encoding.It's best to specify one.
- $out Target encoding.
- $mode auto|iconv|mb_convert_encoding.
Return: New encoded html.
Full url or not.Return bool.
Replace space,process scheme and hosts and remove anchor etc.
Inverse function for parse_url().
Transform uri to full url for currentPage.$urlCurrent should be redirected after 3xx.
Transform full url to uri for currentPage.$urlCurrent should be redirected after 3xx.
Transform full url to dir.$urlCurrent should be redirected after 3xx.
Combine a base URL and a relative URL to produce a new absolute URL.
Filter out "." and ".." segments from a URL's path and return the result.
Return current Curl instance.
All versions of php-curl with dependencies
ext-curl Version *