php-http / curl-client

cURL client
http://httplug.io
MIT License
445 stars 28 forks source link

"Out of memory" sending large files #15

Closed jack-theripper closed 8 years ago

jack-theripper commented 8 years ago

I'm sending a request method PUT

Fatal error: Out of memory (allocated 801898496) (tried to allocate 800528777 bytes) in php-http\curl-client\src\Client.php on line 183

why CURLOPT_POSTFIELDS ?

sample code

$stream = new Stream($file_path, 'rb');
$request = new Request('http://localhost/test.php', 'PUT', $stream);
$response = $client->sendRequest($request);

Description PSR-7 Streams written

Attempting to represent the body of a message as a string can easily consume more memory than intended because the body must be stored completely in memory. Attempting to store the body of a request or response in memory would preclude the use of that implementation from being able to work with large message bodies.

but Client.php reading full body in variable (in memory). what to do?

mekras commented 8 years ago

Please try this Client.php.

jack-theripper commented 8 years ago

Problems with memory is not observed. I checked on a different file sizes.Bug fixed. I think there is an omission, there is no transfer of a body by PATCH method. I suppose necessary to replace

if (in_array($request->getMethod(), ['OPTIONS', 'POST', 'PUT'], true)) {

на

if (in_array($request->getMethod(), ['OPTIONS', 'POST', 'PUT', 'PATCH'], true)) {
sagikazarmark commented 8 years ago

Please stick to using English so that we can follow what happens. Thank you.

mekras commented 8 years ago

I think there is an omission, there is no transfer of a body by PATCH method. I suppose necessary to replace

Please, create a new issue. I'll check it.