PHPackages                             bluepsyduck/multicurl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. bluepsyduck/multicurl

ActiveLibrary[HTTP &amp; Networking](/categories/http)

bluepsyduck/multicurl
=====================

Simple library helping with requesting multiple resources at once using multi cUrl.

2.0.1(8y ago)68.6k↓50%3GPL-2.0PHPPHP &gt;=5.3.0

Since Mar 23Pushed 7y ago2 watchersCompare

[ Source](https://github.com/BluePsyduck/MultiCurl)[ Packagist](https://packagist.org/packages/bluepsyduck/multicurl)[ Docs](https://github.com/BluePsyduck/MultiCurl)[ RSS](/packages/bluepsyduck-multicurl/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (9)Used By (0)

BluePsyduck's MultiCurl Library
===============================

[](#bluepsyducks-multicurl-library)

[![Latest Stable Version](https://camo.githubusercontent.com/d3d365217bfcd9e60db38d5682e7e38c3b0f5ea7ea918de3e9bae7bd7665b2d2/68747470733a2f2f706f7365722e707567782e6f72672f626c75657073796475636b2f6d756c74696375726c2f762f737461626c65)](https://packagist.org/packages/bluepsyduck/multicurl) [![Total Downloads](https://camo.githubusercontent.com/1ccf43bb6433839978c7dae47665a7c54107e962d10565a8112a7e9e395a8921/68747470733a2f2f706f7365722e707567782e6f72672f626c75657073796475636b2f6d756c74696375726c2f646f776e6c6f616473)](https://packagist.org/packages/bluepsyduck/multicurl) [![License](https://camo.githubusercontent.com/c4bce4c2df990f82c2b8dc719f03d8b058426c1ee2c9448b6c01f2897a125376/68747470733a2f2f706f7365722e707567782e6f72672f626c75657073796475636b2f6d756c74696375726c2f6c6963656e7365)](https://packagist.org/packages/bluepsyduck/multicurl) [![Build Status](https://camo.githubusercontent.com/538d8a66491f1b238aca81fc68802363ccc7b486f5d0905d58caedd1b0908125/68747470733a2f2f7472617669732d63692e6f72672f426c75655073796475636b2f4d756c74694375726c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/BluePsyduck/MultiCurl) [![codecov](https://camo.githubusercontent.com/8110284e5e494ca4d028316af391c59d956ad0acb0cfde4a6e662cf0d70f33a1/68747470733a2f2f636f6465636f762e696f2f67682f426c75655073796475636b2f4d756c74694375726c2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/BluePsyduck/MultiCurl)

This library helps with creating and executing multiple requests simultaneously using the Multi-cURL functions of PHP.

Requirements
------------

[](#requirements)

- PHP 7.0 or newer
- PHP cURL extension

Usage
-----

[](#usage)

The main class of the library is the `MultiCurlManager`, to which you can add as many requests as you like and which will execute them. For each request to be started, create an instance of the `Entity\Request` class and set its properties as required, and add it to the manager using `$manager->addRequest($request)`. Added requests will immediately be executed, without blocking the script execution.

To wait for a certain request to finish, call `$manager->waitForSingleRequest($request)`. To wait for all requests to finish, call `$manager->waitForAllRequests()`. These methods will block script execution until the desired requests are finished.

Once a request is finished, use `$request->getResponse()` to get the information of the response. You may want to check `$response->getErrorCode()` and `$response->getErrorMessage()` to get any information in case the request has failed.

The requests offer two callbacks:

- onInitialize: This callback is triggered once the underlying cURL request has been initialized. Use this callback to further manipulate the cURL. After this callback, the cURL request gets executed.
- onComplete: This callback is triggered once the cURL request finished and the response has been parsed into the entity.

Examples
--------

[](#examples)

Here is a basic example demonstrating the use of the `MultiCurlManager`:

```
