Download the PHP package xsuchy09/rolling-curl without Composer
On this page you can find all versions of the php package xsuchy09/rolling-curl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xsuchy09/rolling-curl
More information about xsuchy09/rolling-curl
Files in xsuchy09/rolling-curl
Package rolling-curl
Short Description Rolling-Curl: A non-blocking, non-dos multi-curl library for PHP
License Apache-2.0
Homepage https://github.com/xsuchy09/rolling-curl
Informations about the package rolling-curl
RollingCurl
A cURL library to fetch a large number of resources while maintaining a consistent number of simultaneous connections
Authors:
- Jeff Minard (jrm.cc)
- Josh Fraser (joshfraser.com)
- Alexander Makarov (rmcreative.ru)
- Petr Suchy (xsuchy09 - www.wamos.cz)
Overview
RollingCurl is a more efficient implementation of curl_multi().
curl_multi is a great way to process multiple HTTP requests in parallel in PHP but suffers from a few faults:
- The documentation for curl_multi is very obtuse and, as such, is easy to incorrectly or poorly implement
- Most curl_multi examples queue up all requests and execute them all at once
The second point is the most important one for two reasons:
- If you have to wait on every single request to complete, your program is "blocked" by the longest running request.
- More importantly, when you run a large number of cURL requests simultaneously you are, essentially, running a DOS attack. If you have to fetch hundreds or even thousands of URLs you're very likely to be blocked by automatic DOS systems. At best, you're not being a very respectful citizen of the internet.
RollingCurl deals with both issues by maintaining a maximum number of simultaneous requests and "rolling" new requests into the queue as existing requests complete. When requests complete, and while other requests are still running, RollingCurl can run an anonymous function to process the fetched result. (You have the option to skip the function and instead process all requests once they are done, should you prefer.)
Installation (via composer)
Get composer and add this in your requires section of the composer.json:
and then
Usage
Basic Example
Fetch A Very Large Number Of Pages
Let's scrape google for the first 500 links & titles for "curl"
Setting custom curl options
For every request
For a single request:
Changes
3.1.5:
- Request::getActualExecutionTime added.
3.1.4:
- Timeouts - default timeouts set to 5s for CURLOPT_CONNECTTIMEOUT and 20s for CURLOPT_TIMEOUT.
3.1.3:
- Request - private vars and functions are protected now
3.1.2:
- Every request has start, end (DateTime with microseconds) - so we know executionTime of everyRequest - @see Request::getExecutionTime and Request::getExecutionTimeMicroseconds
- RollingCurl::wasIdleCallbackCalled added - idleCallback may not be called it requests are handled too much quickly - you can check if idleCallback was called or not.
- Some comments and methods parameters definition.
More examples can be found in the examples/ directory.
TODO:
- PHPUnit test
- Ensure PSR spec compatibility
- Fix TODOs
- Better validation on setters
Feel free to fork and pull request to help out with the above. :D
Similar Projects
All versions of rolling-curl with dependencies
ext-curl Version *
lib-curl Version *