{"id":13658343,"url":"https://github.com/jmathai/php-multi-curl","last_synced_at":"2025-04-08T15:14:16.041Z","repository":{"id":800254,"uuid":"501306","full_name":"jmathai/php-multi-curl","owner":"jmathai","description":"A high performance PHP library for using multi curl for parallel http calls.","archived":false,"fork":false,"pushed_at":"2020-12-17T07:34:16.000Z","size":35,"stargazers_count":373,"open_issues_count":8,"forks_count":97,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-04-01T14:14:06.298Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmathai.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"jmathai"}},"created_at":"2010-02-03T20:58:43.000Z","updated_at":"2025-03-23T00:18:53.000Z","dependencies_parsed_at":"2022-07-05T16:01:05.255Z","dependency_job_id":null,"html_url":"https://github.com/jmathai/php-multi-curl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmathai%2Fphp-multi-curl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmathai%2Fphp-multi-curl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmathai%2Fphp-multi-curl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmathai%2Fphp-multi-curl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmathai","download_url":"https://codeload.github.com/jmathai/php-multi-curl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247867362,"owners_count":21009240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T05:00:58.872Z","updated_at":"2025-04-08T15:14:16.010Z","avatar_url":"https://github.com/jmathai.png","language":"PHP","funding_links":["https://github.com/sponsors/jmathai"],"categories":["PHP"],"sub_categories":[],"readme":"PHP-multi-curl\n==============\nHigh performance PHP curl wrapper to make parallel HTTP calls\n\n[![Build Status](https://travis-ci.org/jmathai/php-multi-curl.svg)](https://travis-ci.org/jmathai/php-multi-curl) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jmathai/php-multi-curl/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jmathai/php-multi-curl/?branch=master)\n\n## Contents\n\n* [Installation](#installation)\n* [Usage](#usage)\n* [Advanced Usage](#advanced-usage)\n* [Documentation](#documentation)\n  * [Methods](#methods)\n    * [addUrl](#addurl)\n    * [addCurl](#addcurl)\n    * [renderAscii](#renderascii)\n  * [Accessing Response](#accessing-response)\n    * [response](#response)\n    * [code](#code)\n    * [headers](#headers)\n\n## Installation\n\nYou can use composer to install this library from the command line.\n\n```\ncomposer require jmathai/php-multi-curl:dev-master -v\n```\n\n## Usage\n\nBasic usage can be done using the `addUrl($url/*, $options*/)` method. This calls `GET $url` by passing in `$options` as the parameters.\n```php\n\u003c?php\n  // Include Composer's autoload file if not already included.\n  require '../vendor/autoload.php';\n\n  // Instantiate the MultiCurl class.\n  $mc = JMathai\\PhpMultiCurl\\MultiCurl::getInstance();\n\n  // Make a call to a URL.\n  $call1 = $mc-\u003eaddUrl('http://slowapi.herokuapp.com/delay/2.0');\n  // Make another call to a URL.\n  $call2 = $mc-\u003eaddUrl('http://slowapi.herokuapp.com/delay/1.0');\n\n  // Access the response for $call2.\n  // This blocks until $call2 is complete without waiting for $call1\n  echo \"Call 2: {$call2-\u003eresponse}\\n\";\n\n  // Access the response for $call1.\n  echo \"Call 1: {$call1-\u003eresponse}\\n\";\n\n  // Output a call sequence diagram to see how the parallel calls performed.\n  echo $mc-\u003egetSequence()-\u003erenderAscii();\n```\n\nThis is what the output of that code will look like.\n\n```\nCall 2: consequatur id est\nCall 1: in maiores et\n(http://slowapi.herokuapp.com/delay/2.0 ::  code=200, start=1447701285.5536, end=1447701287.9512, total=2.397534)\n[====================================================================================================]\n(http://slowapi.herokuapp.com/delay/1.0 ::  code=200, start=1447701285.5539, end=1447701287.0871, total=1.532997)\n[================================================================                                    ]\n```\n\n## Advanced Usage\n\nYou'll most likely want to configure your cURL calls for your specific purpose. This includes setting the call's HTTP method, parameters, headers and more. You can use the `addCurl($ch)` method and configuring your curl handle using any of PHP's `curl_*` functions.\n\n```php\n\u003c?php\n  $mc = JMathai\\PhpMultiCurl\\MultiCurl::getInstance();\n\n  // Set up your cURL handle(s).\n  $ch = curl_init('http://www.google.com');\n  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);\n  curl_setopt($ch, CURLOPT_POST, 1);\n  \n  // Add your cURL calls and begin non-blocking execution.\n  $call = $mc-\u003eaddCurl($ch);\n  \n  // Access response(s) from your cURL calls.\n  $code = $call-\u003ecode;\n```\n\nYou can look at the [tests/example.php](https://github.com/jmathai/php-multi-curl/blob/master/src/example.php) file for working code and execute it from the command line.\n\n## Documentation\n\n### Methods\n#### addUrl\n\n`addUrl((string) $url/*, (array) $options*/)`\n\nMakes a `GET` call to `$url` by passing the key/value array `$options` as parameters. This method automatically sets `CURLOPT_RETURNTRANSFER` to `1` internally.\n\n```php\n$call = $mc-\u003eaddUrl('https://www.google.com', array('q' =\u003e 'github'));\necho $call-\u003eresponse;\n```\n\n#### addCurl\n\n`addCurl((curl handle) $ch)`\n\nTakes a curl handle `$ch` and executes it. This method, unlike `addUrl`, will not add anything to the cURL handle. You'll most likely want to set `CURLOPT_RETURNTRANSFER` yourself before passing the handle into `addCurl`.\n\n```php\n$ch = curl_init('http://www.mocky.io/v2/5185415ba171ea3a00704eed');\ncurl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');\n\n$call = $mc-\u003eaddCurl($ch);\necho $call-\u003eresponse;\n```\n\n### Accessing Response\n\nThe curl calls begin executing the moment you call `addUrl` or `addCurl`. Execution control is returned to your code immediately and blocking for the response does not occur until you access the `response` or `code` variables. The library only blocks for the call you're trying to access the response to and will allow longer running calls to continue to execute while returning control back to your code.\n\n#### response\n\nThe `response` variable returns the `string` text of the response.\n\n```php\necho $call-\u003eresponse;\n```\n\n#### code\n\nThe `code` variable returns the `integer` HTTP response code of the request.\n\n```php\necho $call-\u003ecode;\n```\n\n#### headers\n\nThe `headers` variable returns an `array` of HTTP headers from the response.\n\n```php\nvar_dump($call-\u003eheaders);\n```\n\n#### renderAscii\n\nReturn a `string` that prints out details of call latency and degree of being called in parallel. This method can be called indirectly through the multi-curl instance you're using.\n\n```php\necho $mc-\u003egetSequence()-\u003erenderAscii();\n```\n\n## Authors\n   * jmathai\n   \n### Contributors\n   * Lewis Cowles (LewisCowles1986) - Usability for adding url's without needing to worry about CURL, but provisioning also for specifying additional parameters\n   * Sam Thomson (samthomson) - Packaged it up\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmathai%2Fphp-multi-curl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmathai%2Fphp-multi-curl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmathai%2Fphp-multi-curl/lists"}