-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support streaming bodies in the client #15
Comments
Hello :-), The So, because this response from QED ■. |
The point of this ticket is, that someone may be using the library to do downloads of very large files. In those cases, we want to ensure that the entire file is accessed as a stream, and never placed into memory. So while it's possible right now to convert the string into a stream, the goal is to change the client a bit so it uses a stream under the hood as well. |
@evert But the result is already in memory because cURL gives you all the “stuff”: https://github.com/fruux/sabre-http/blob/c55cbc1daa91293cda92ea4b90de79c743c4a149/lib/Client.php#L483. I will check if cURL can gives only few informations in order to create a stream. |
An interesting link from a friend of me @pmartin: http://stackoverflow.com/questions/1342583/manipulate-a-string-that-is-30-million-characters-long/1342760#1342760. However, I don't know how it works if we don't want to load the response yet we receive it but later: When reading the stream only. |
In case where the user has a stream ready and with the write permission, she can give this stream to the HTTP client and the response will be copied into this stream. This answer to one use-case. |
streams in request bodies already 100% work, this is about turning a HTTP response into a stream. |
@evert How does it work. I missed it in the source code? |
@evert Yup, it's for sending a request. What you would like to do is for receiving a response, right? |
Indeed, yes! |
Any news on this? I am very interrested in using streams as im going to down/upload large files >2GB with the webdav client. |
@h44z Not from me yet. |
This is still something that interesting for us, but we haven't had time implementing it yet. |
So the problem here is that curl actually doesn't have an easy way for us to just access the stream resource, as far as I can tell. The only way we can progressively get access to the stream, is by using the With that function, we could send everything to a temporary stream ( Ideally we'd want the response to return as soon as it starts coming in and not after all the bytes have arrived, and ideally we would want to not have to cache/buffer it anywhere. I don't see an easy way to do that. |
Which parts of the problem doesnt this solve for you, could you elaborate? |
Well, it would be really nice if we can do something like : $request = "...";
$response = $client->send($request);
stream_copy_to_stream('php://output', $response->getBodyAsStream()); This should:
|
Absolutely. So we need to change from using a string and use e.g. a php tmp stream in this will be not "real" streaming but it will be way better as what we have ATM. |
The problem with using the temporary stream is that it only partially solve the goals. It does not:
|
It's better than nothing though. |
right, but thats how streaming works nevertheless...
hm IIRC we could do this using a non-blocking read/write stream, couldn't we? |
maybe it would also be a good occasion to use a different http client, e.g. https://github.com/amphp/artax (so we dont need to workaround curl limitations) |
That's not really true... If I didn't use curl and used PHP's built-in HTTP stream wrappers, there would be no buffer. Here's an example (and note that I did stream_copy_to_stream() wrong in my previous code snippet, sorry about that): stream_copy_to_stream(
fopen('http://example.org/','r'),
fopen('php://output','w')
); If I do the same with a temporary stream, it would look more like this: $tmp = fopen('php://temp','r+');
stream_copy_to_stream(
fopen('http://example.org/','r'),
fopen($tmp,'w')
);
rewind($tmp);
stream_copy_to_stream(
$tmp,
fopen('php://output','w')
); This last example has two passes, and requires a buffer (disk or memory depending on the size) and this is exactly how the curl example with
Not at the same time, and not without a buffer. Perhaps with
Not a bad idea =) |
I think the only really good solution will be a different http client. |
I'll definitely look into it. My preference would go for something lightweight, so maybe artax is that =) In the future I want to kick of sabre/davclient again, so that will be good timing to dig into that. |
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82, Remove the substr function in `parseCurlResult()` and register receiveCurlHeader as callback function by using CURLOPT_HEADERFUNCTION instead, To avoid additional memory copy of response body (from $response to $responseBody). This changes is not intended to resolve issue sabre-io#15
In order to resolve sabre-io#82 to avoid additional memory copy of response body (from $response to $responseBody), We deperecated `parseCurlResult` method which use `substr` function to separate HTTP headers and body and create new method `parseCurlResponse` instead. We register `receiveCurlHeader` method as callback function by curl_setopt using `CURLOPT_HEADERFUNCTION` option. This changes is not intended to resolve issue sabre-io#15 See sabre-io#115 (comment)
In order to resolve sabre-io#82 to avoid additional memory copy of response body (from $response to $responseBody), We deperecated `parseCurlResult` method which use `substr` function to separate HTTP headers and body and create new method `parseCurlResponse` instead. We register `receiveCurlHeader` method as callback function by curl_setopt using `CURLOPT_HEADERFUNCTION` option. This changes is not intended to resolve issue sabre-io#15 See sabre-io#115 (comment)
In order to resolve sabre-io#82 to avoid additional memory copy of response body (from $response to $responseBody), We deperecated `parseCurlResult` method which use `substr` function to separate HTTP headers and body and create new method `parseCurlResponse` instead. We register `receiveCurlHeader` method as callback function by curl_setopt using `CURLOPT_HEADERFUNCTION` option. This changes is not intended to resolve issue sabre-io#15 See sabre-io#115 (comment)
In order to resolve #82 to avoid additional memory copy of response body (from $response to $responseBody), We deperecated `parseCurlResult` method which use `substr` function to separate HTTP headers and body and create new method `parseCurlResponse` instead. We register `receiveCurlHeader` method as callback function by curl_setopt using `CURLOPT_HEADERFUNCTION` option. This changes is not intended to resolve issue #15 See #115 (comment)
Moved from here:
https://github.com/fruux/sabre-dav/issues/321
The text was updated successfully, but these errors were encountered: