I am using Symfony and one feature is to upload some files to Google Drive. This behavior is triggered when an external API (which I don't have control on) sends a request on a specific route.
The problem is that the upload of the files to the Drive takes some times, and the remote API justs timeout waiting for a response.
I went online to do some search and found that I can use Listeners : https://symfony.com/doc/current/components/event_dispatcher.html#connecting-listeners
The problem is with all that setup, the response is still taking the same time.
Service ctor :
private $eventDispatcher;
public function __construct(EventDispatcherInterface $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
}
Here is the code in my Service, uploadFileToDriveMultiple(...)
function :
$this->eventDispatcher->addListener(KernelEvents::TERMINATE, function (Event $event) use ($prmParentFolderIdArray, $prmFilesNamesArray, $prmFilesPathsArray) {
// Upload here
});
And in the Controller :
$serviceDrive->uploadFileToDriveMultiple($filesParent, $filesName, $filesPath);
Did I miss setting up something ? Any help is appreciated
Thank you !
CodePudding user response:
It turns out I just needed php-fpm
which will use fastcgi_finish_request
: https://www.php.net/manual/en/function.fastcgi-finish-request.php
After modifying my DockerFile and rebuilding an image, it works perfectly.
The code works with php
aswell, but you'll get no benefits from it, so if you're trying to achieve the same thing, be sure to use php-fpm