Comments (2)
@rpstevefysh, it's understandable and comes from the nature of PHP. While the server is working, the client is waiting. You don't have any performance issues, server overloads, or something like that — everything really works as expected.
What you do see is network communications. While the file is being uploaded from the Uploadcare server instance to the S3 bucket, you will not receive a response and can't do anything in the current PHP process.
My only advice here is to use a queue on your side to make this operation asynchronous. I know it requires some infrastructure changes (at least, you have to have a queue manager and run the command on a server), but those changes are not so big and pretty understandable. For example, you can use the Redis service to make a queue and a simple SystemD configuration to keep it working.
Then, you can make a few messages with parameters and send them to the bus. Something like
<?php
final class CopyToRemoteMessage()
{
public function __construct(
readonly private string $sourceUrl,
readonly private string $target,
readonly private string $targetPattern,
) {}
// ... your getters for properties
}
as the message class, and simply make those messages in your controller and send them
$original_target_pattern = $folder . '/' . $newFilenameWithTimestamp;
/**
* Do not forget to inject the MessageBusInterface into your controller.
* After this call, your code will continue immediately, and a message will be processed in a consumer (see below).
*/
$this->bus->dispatch(new CopyToRemoteMessage($source_uuid, $target, $original_target_pattern));
And example consumer could be list this:
<?php
use Uploadcare\Api;
final class CopyToRemoteConsumer
{
public function __construct(
readonly private Api $api,
) {}
public function __invoke(CopyToRemoteMessage $message): void
{
$this->api->file()->copyToRemoteStorage($message->getSourceUrl(), true, $message->getTarget(), $message->getTargetPattern());
}
}
In this way, you'll have a controller method that answers in milliseconds and a background process related to the actual uploading process. Of course, it will not speed up the uploading process itself; you'll have to wait a bit before that file is really uploaded to the S3 storage and check its state, but this will give you flexibility in a matter of user experience.
Please check the Uploadcare PHP repository for examples of dependency injections and configurations.
from uploadcare-php.
Thank you for your response. This makes sense and we will pursue the queue options.
from uploadcare-php.
Related Issues (20)
- Tests for all non-tested
- Add a `$custom_headers` parameter to `createRemoteCopy` HOT 1
- Group files info HOT 1
- Concrete class for Akamai CDN token and expire generation
- FileApi.php HOT 9
- Missing URL on File in FileCollection when fetching it from group HOT 4
- Secure Delivery File Transformations Not Working HOT 4
- Access to the raw json response HOT 2
- Question: How do I get the original Image Dimensions HOT 1
- How to get dimensions of an image of a transformed URL? HOT 2
- getOriginalFileUrl() sometimes returns empty string HOT 1
- deleteFile pitches Guzzle Method Not Allowed error HOT 2
- Deprecate PUT /group/{uuid}/storage/ HOT 1
- Show default_effects in file info of group info response HOT 2
- Update webhooks API (event types and versioning)
- Add AWS Rekognition Moderation
- multipage conversion (save_in_group param in documentJobSubmitParameters)
- Signed URL updates
- Update signed URLs implementation to work with ~ and ,
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uploadcare-php.