-
Notifications
You must be signed in to change notification settings - Fork 11
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
[FEATURE] Send files directly with Swoole Response. #6
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi !
Please, could you provide examples of how are you using this feature?
Thank you!
I'm using this Swoole's feature to send quite large files directly with Swoole server and avoid in-memory copying. This trick allowed me to return files faster. My example: public function get(Response $response, array $data): Response
{
$this->validate($data);
$media = $this->getMedia(intval($data['mediaId']));
return $response
->withHeader('Content-Type', $media->mediaType)
->withHeader('Content-Transfer-Encoding', 'binary')
->withHeader('Expires', date(DateTimeFormat::HTTP, time() + self::HEADER_CACHE_TIME))
->withHeader('Cache-Control', 'max-age=' . self::HEADER_CACHE_TIME)
->withBody(
(new StreamFactory())->createStreamFromFile($media->originPath, 'rb')
);
} |
Thank you for the example! I'm not able to get
Which factory are you using to execute the createStreamFromFile function? I'm asking this because I would like to know if the trick you're proposing can be used with different PSR factories. Thanks again! |
It is a good point. Thank you! I'm using Slim's Factory and my whole example is here.
Finally I found the root cause... Coroutines were enabled in my code: Anyway I will improve my code to handle both cases. When done I will update the pull request. |
Nice catch! Now I'm able to get the "/coroutine" too. Thank you! |
@imefisto I've committed the fix to handle both cases. |
I'm merging now, then I'll add a test case for the feature. Thank you very much! |
Send files directly with Swoole Response.