{"id":21212565,"url":"https://github.com/aternosorg/php-curl-psr","last_synced_at":"2026-01-12T09:47:23.826Z","repository":{"id":263607251,"uuid":"890914658","full_name":"aternosorg/php-curl-psr","owner":"aternosorg","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-10T11:57:05.000Z","size":84,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T16:05:58.866Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/aternosorg.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2024-11-19T12:03:33.000Z","updated_at":"2025-03-10T11:55:45.000Z","dependencies_parsed_at":"2024-11-19T13:37:30.138Z","dependency_job_id":"452f312b-6f80-49e4-aa6a-7dfcdf1079f2","html_url":"https://github.com/aternosorg/php-curl-psr","commit_stats":null,"previous_names":["aternosorg/php-curl-psr"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aternosorg%2Fphp-curl-psr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aternosorg%2Fphp-curl-psr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aternosorg%2Fphp-curl-psr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aternosorg%2Fphp-curl-psr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aternosorg","download_url":"https://codeload.github.com/aternosorg/php-curl-psr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788855,"owners_count":21161726,"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-11-20T21:11:04.201Z","updated_at":"2026-01-12T09:47:23.812Z","avatar_url":"https://github.com/aternosorg.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aternos/curl-psr\n\nA simple PSR-18 client implementation based on cURL that actually supports\nstreaming both requests and responses.\n\n## Installation\n\n```bash\ncomposer require aternos/curl-psr\n```\n\nIn addition to [PSR-18 (HTTP Client)](https://www.php-fig.org/psr/psr-18/), this library also provides\nimplementations for [PSR-17 (HTTP Factories)](https://www.php-fig.org/psr/psr-17/) and\n[PSR-7 (HTTP Messages)](https://www.php-fig.org/psr/psr-7/), so no other implementations need to be installed.\n\n## Usage\n\n### Creating a client\n\n```php\n$client = new \\Aternos\\CurlPsr\\Psr18\\Client();\n```\n\nWhen creating a client, you can optionally provide PSR-17 `ResponseFactoryInterface` and `UriFactoryInterface` instances.\nBy default, the client will use the `Aternos\\CurlPsr\\Psr17\\Psr17Factory` class included in this library.\n\nAdditionally, you can pass an optional `UriResolverInterface` instance, which is used to resolve redirect targets.\n\n### Configuring the client\n\nSince PSR-7 does not offer many request options, you can set client-wide options that are used for all requests.\nRequests will use the client options as they are at the moment they are sent.\nChanging client options will therefore not affect already running requests.\n\n```php\n$client-\u003esetTimeout(10) // Set the timeout to 10 seconds\n       -\u003esetMaxRedirects(5) // Set the maximum number of redirects to follow to 5\n       -\u003esetCookieFile(\"/path/to/cookie/file\") // Set the path to the cURL cookie file \n       -\u003esetCurlOption(CURLOPT_DNS_SHUFFLE_ADDRESSES, true) // Set a custom cURL option\n       -\u003esetDefaultHeaders([\"User-Agent\" =\u003e [\"MyClient/1.0\"]]) // Set default headers for all requests\n       -\u003eaddDefaultHeader(\"Accept\", \"application/json\"); // Add a default header\n\n$client-\u003esetProgressCallback(function (\n    \\Psr\\Http\\Message\\RequestInterface $request, \n    int $downloadTotal, \n    int $downloaded, \n    int $uploadTotal, \n    int $uploaded\n) {\n    // Progress callback\n});\n```\n\n#### Custom cURL options\n\nYou can set custom cURL options using the `setCurlOption` method. Note that some options cannot be set, since they are \nused internally by the client.\n\n#### Redirects\n\nThe client will follow redirects by default. You can set the maximum number of redirects to follow using the \n`setMaxRedirects` method. It is also possible to disable redirects using `setFollowRedirects`. The difference between\nsetting the maximum number of redirects to 0 and disabling redirects is that the former will throw an exception if a\nredirect is received, while the latter will simply return the redirect response.\n\nOnly when status `303 See Other` is received, the client will automatically change the request method to `GET` and\nremove the request body. Historically, this behavior was also sometimes present for `301` and `302`, so it is possible\nto enable it for other status codes using the `setRedirectToGetStatusCodes` method.\n\nStatus `300 Multiple Choices` will only be treated as a redirect if the `Location` header is present.\nOtherwise, the response will be returned as is.\n\nTo manage how redirect targets are resolved, or limit what locations the client can be redirected to,\nyou can pass an instance of `UriResolverInterface` to the client constructor.\n\nWhen a redirect response is received that does not prompt the client to change the request method to `GET`\nand the body stream cannot be rewound, an exception is thrown. This is because the client cannot resend the request\nwith the same body stream.\n\n#### Progress callback\n\nThe progress callback function works the same way as the `CURLOPT_PROGRESSFUNCTION` in cURL,\nexcept that it receives the PSR-7 request object instead of a cURL handle as the first argument.\nPlease note that the request object passed to the callback is not necessarily same instance that was\noriginally passed to the `sendRequest` method. This is because PSR-7 request objects are immutable,\nso the client will create a new request object if changes are necessary (e.g. to add default headers).\n\n### Sending a request\n\n```php\n$factory = new \\Aternos\\CurlPsr\\Psr17\\Psr17Factory();\n\n$request = $factory-\u003ecreateRequest(\"GET\", \"https://example.com\")\n    -\u003ewithHeader(\"X-Some-Header\", \"Some Value\");\n    -\u003ewithBody($streamFactory-\u003ecreateStream(\"Some body\"));\n\n$response = $client-\u003esendRequest($request);\n\n$headers = $response-\u003egetHeaders();\n$stream = $response-\u003egetBody();\n\necho $stream-\u003egetContents();\n```\n\nCurlPsr can send any PSR-7 request object and return a PSR-7 response object. For more information on how to use PSR-7 objects,\nsee the [PSR-7 documentation](https://www.php-fig.org/psr/psr-7/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faternosorg%2Fphp-curl-psr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faternosorg%2Fphp-curl-psr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faternosorg%2Fphp-curl-psr/lists"}