{"id":13704182,"url":"https://github.com/php-mod/curl","last_synced_at":"2025-05-14T05:10:38.656Z","repository":{"id":409345,"uuid":"14077036","full_name":"php-mod/curl","owner":"php-mod","description":"This library provides an object-oriented and dependency free wrapper of the PHP cURL extension.","archived":false,"fork":false,"pushed_at":"2025-02-11T10:11:57.000Z","size":3444,"stargazers_count":325,"open_issues_count":2,"forks_count":121,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-04T15:02:44.699Z","etag":null,"topics":["curl","hacktoberfest","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-mod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-11-02T23:32:24.000Z","updated_at":"2025-04-01T06:29:39.000Z","dependencies_parsed_at":"2024-01-12T10:25:56.574Z","dependency_job_id":"4476ec59-cfe5-4191-9246-50a16f6e1289","html_url":"https://github.com/php-mod/curl","commit_stats":{"total_commits":207,"total_committers":29,"mean_commits":7.137931034482759,"dds":0.6570048309178744,"last_synced_commit":"f207b53643ad176448c6e9644ee91d5557b1c32c"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mod%2Fcurl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mod%2Fcurl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mod%2Fcurl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mod%2Fcurl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-mod","download_url":"https://codeload.github.com/php-mod/curl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253505664,"owners_count":21918942,"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":["curl","hacktoberfest","php"],"created_at":"2024-08-02T21:01:05.294Z","updated_at":"2025-05-14T05:10:38.614Z","avatar_url":"https://github.com/php-mod.png","language":"PHP","funding_links":[],"categories":["目录","HTTP"],"sub_categories":["HTTP客户端 HTTP Client"],"readme":"# PHP Curl Class\n\nThis library provides an object-oriented and dependency free wrapper of the PHP cURL extension.\n\n[![Maintainability](https://api.codeclimate.com/v1/badges/6c34bb31f3eb6df36c7d/maintainability)](https://codeclimate.com/github/php-mod/curl/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/6c34bb31f3eb6df36c7d/test_coverage)](https://codeclimate.com/github/php-mod/curl/test_coverage)\n[![Total Downloads](https://poser.pugx.org/curl/curl/downloads)](//packagist.org/packages/curl/curl)\n[![Tests](https://github.com/php-mod/curl/actions/workflows/tests.yml/badge.svg)](https://github.com/php-mod/curl/actions/workflows/tests.yml)\n\nIf you have questions or problems with installation or usage [create an Issue](https://github.com/php-mod/curl/issues).\n\n## Installation\n\nIn order to install this library via composer run the following command in the console:\n\n```sh\ncomposer require curl/curl\n```\n\n## Usage examples\n\nA few example for using CURL with get:\n\n```php\n$curl = (new Curl\\Curl())-\u003eget('http://www.example.com/');\nif ($curl-\u003eisSuccess()) {\n    // do something with response\n    var_dump($curl-\u003eresponse);\n}\n// ensure to close the curl connection\n$curl-\u003eclose();\n```\n\nOr with params, values will be encoded with `PHP_QUERY_RFC1738`:\n\n```php\n$curl = (new Curl\\Curl())-\u003eget('http://www.example.com/search', [\n    'q' =\u003e 'keyword',\n]);\n```\n\nAn example using post\n\n```php\n$curl = new Curl\\Curl();\n$curl-\u003epost('http://www.example.com/login/', [\n    'username' =\u003e 'myusername',\n    'password' =\u003e 'mypassword',\n]);\n```\n\nAn exampling using basic authentication, remove default user agent and working with error handling\n\n```php\n$curl = new Curl\\Curl();\n$curl-\u003esetBasicAuthentication('username', 'password');\n$curl-\u003esetUserAgent('');\n$curl-\u003esetHeader('X-Requested-With', 'XMLHttpRequest');\n$curl-\u003esetCookie('key', 'value');\n$curl-\u003eget('http://www.example.com/');\n\nif ($curl-\u003eerror) {\n    echo $curl-\u003eerror_code;\n} else {\n    echo $curl-\u003eresponse;\n}\n\nvar_dump($curl-\u003erequest_headers);\nvar_dump($curl-\u003eresponse_headers);\n```\n\nExample access to curl object:\n\n```php\ncurl_set_opt($curl-\u003ecurl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1');\ncurl_close($curl-\u003ecurl);\n```\n\nExample of downloading a file or any other content\n\n```php\n$curl = new Curl\\Curl();\n// open the file where the request response should be written\n$file_handle = fopen($target_file, 'w+');\n// pass it to the curl resource\n$curl-\u003esetOpt(CURLOPT_FILE, $file_handle);\n// do any type of request\n$curl-\u003eget('https://github.com');\n// disable writing to file\n$curl-\u003esetOpt(CURLOPT_FILE, null);\n// close the file for writing\nfclose($file_handle);\n```\n\n## Testing\n\nIn order to test the library:\n\n1. Create a fork\n2. Clone the fork to your machine\n3. Install the depencies `composer install`\n4. Build and start the docker image (in `tests/server`) `docker build . -t curlserver` start `docker run -p 1234:80 curlserver`\n5. Run the unit tests `./vendor/bin/phpunit tests`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-mod%2Fcurl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-mod%2Fcurl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-mod%2Fcurl/lists"}