Why is Oneup/UploaderBundle so slow to upload a 'big' file (1GB)? - symfony

In a Symfony project, I have implemented the Oneup/UploaderBundle with the Oneup/FlysystemBundle to upload files to a S3 compatible storage.
I tried to upload a 1GB file, and it took about 3 min using the Aws\S3\S3Client adapter (https://flysystem.thephpleague.com/docs/adapter/aws-s3-v3/), which is way too slow.
oneup_uploader.yaml :
object_scaleway_sync:
frontend: dropzone
storage:
type: flysystem
filesystem: oneup_flysystem.object_scaleway_sync_filesystem
oneup_flysystem.yaml :
oneup_flysystem:
adapters:
xxx_fr_sync.flysystem_adapter:
awss3v3:
client: xxx_fr.sync_s3_client
bucket: 'xxxtest'
prefix: ''
filesystems:
object_scaleway_sync:
adapter: xxx_fr_sync.flysystem_adapter
After that, I tried to upload the same file using directly the S3Client in a controller, and it took about 98 seconds, which is faster, but still too slow for 1GB.
MainController.php :
$client = new S3S3Client([
'region' => 'fr-par',
'endpoint' => 'https://s3.fr-par.scw.cloud',
'version' => 'latest',
'credentials' => [
'key' => 'publickey',
'secret' => 'secretkey'
]
]);
$pathToFile = $this->getParameter('kernel.project_dir') . '/public/big.bin';
$resource = \fopen($pathToFile, 'r');
$result = $client->putObject([
'Bucket' => 'xxxtest',
'Key' => 'big.bin',
'Body' => $resource
]);
return new Response("Ok");
Strangely, this simple plain php script below took 28 seconds to upload the same file :
$s3 = new Aws\S3\S3Client([
'region' => 'fr-par',
'version' => 'latest',
'endpoint' => 'https://s3.fr-par.scw.cloud',
'credentials' => [
'key' => "publickey",
'secret' => "secretkey",
]
]);
$result = $s3->putObject([
'Bucket' => 'xxxtest',
'Key' => 'big.bin',
'SourceFile' => './big.bin'
]);
Why is this script faster than the Symfony method ? Is there a way to optimize the upload speed ?
I tried using the async S3 Simple Client (https://async-aws.com/integration/simple-s3.html) but it returned the error "Could not contact remote server" at the end of the upload.
Same error with the async S3Client (https://async-aws.com/clients/s3.html).

Related

WP Offload Media Lite - return s3 image url

I created a page that will allow admins to upload logos. These logos will be saved in the media folder as well as in the S3 bucket.
I am using the WP Offload Media Lite to upload any saved files/images in wordpress into my S3 bucket. I have that part working well and everything is saving properly but what i realized that i need the S3 url image to be saved in the metadata of the image.
How can i return the created the image url saved in S3 or have the url saved in metadata for the image?
This is my current code for uploading file/images. This uploads to the media library which also uploads to S3:
$file = array(
'name' => $_FILES["profile_logo"]["name"],
'type' => $_FILES["profile_logo"]["type"],
'tmp_name' => $_FILES["profile_logo"]["tmp_name"],
'size' => $_FILES["profile_logo"]["size"]
);
$upload = wp_handle_upload($file, array('test_form' => false));
if(!empty($upload['error'])){
echo "some error";
return false;
}
$check_page_exist = get_page_by_title($user->slug, OBJECT, 'page');
$attachment_id = wp_insert_attachment(array(
'guid' => $upload['url'],
'post_mime_type' => $upload['type'],
'post_title' => basename($upload['file']),
'post_content' => '',
'post_status' => 'inherit'
), $upload['file'], $check_page_exist->ID);
if(is_wp_error($attachment_id) || !$attachment_id){
wp_die('Upload error.');
}
wp_update_attachment_metadata($attachment_id, wp_generate_attachment_metadata($attachment_id, $upload['file']));

Connect silex 2 dbal connect app engine with cloud sql

I lost several hours trying to connect to cloud SQL from PHP flex env, but I found the answer.
I hope this help other people.
An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory
or
Access denied for user 'root'#'cloudsql' (using password: NO)
1.- enable Google Cloud SQL API: https://console.cloud.google.com/apis/
2.- get your cloud sql instance name
3.- add the beta_settings to your yaml
beta_settings:
cloud_sql_instances: "here-your-instance-name"
4.- config your doctrine dbal unix_socket
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
'dbs.options' => array (
'db_conn' => array(
'driver' => 'pdo_mysql',
'unix_socket' => '/cloudsql/here-your-instance-name',
'host' => 'localhost',
'dbname' => 'your-database',
'user' => 'your-user',
'password' => 'your-password',
'charset' => 'utf8',
'collate' => 'utf8_spanish2_ci'
)
)
));

how to create uninstall webhook in shopify using laravel wrapper?

i am trying to create webhook using the api call inlaravel but it gives me the error "The requested URL returned error: 406 Not Acceptable".
my code is as bellow.
$webhookData = [
'webhook' => [
'topic' => 'app/uninstalled',
'address' => url('/uninstall'),
'fields' => 'name',
'format' => 'json'
]
];
$uninstall = $sh->call(['URL' => 'https://' . $shop . '/admin/webhooks.json', 'METHOD' => 'POST', 'DATA' => $webhookData]);
There are certain things you need to take care of while creating the Shopify webhooks.
The address field should be a globally accessible URL (ex: https://example.com/webhook/uninstall.php)
You can not give localhost links for creating webhooks.
I think the address field is not passed with a valid URL in your post request.

Yii2 console script not working

I want to automatically download my database backup weekly. I'm using xampp on windows. I've google around and found that I've to make use of windows task scheduler and the action script in my console controller. I've read this and this and tried running the command from command prompt. I'm getting 'Unknown command'.
My code in console controller for now just for testing
<?php
namespace console\controllers;
use Yii;
use yii\console\Controller;
/**
* Cron controller
*/
class TestController extends Controller {
public function actionIndex() {
echo "cron service runnning";
}
}
And my main config file
<?php
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'console\controllers',
'components' => [
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
],
'modules' => [
'rbac' => [
'class' => 'johnitvn\rbacplus\Module'
]
],
'params' => $params,
];
The error I'm getting
Make sure you have TestController.php file in console/controllers folder and its name is written correctly.
Then from project root folder you can call your command like that:
php yii test/index
or just:
php yii test
(because index is a default action (configured in $defaultAction) and you can omit it).
If you are outside of project folder, make sure to provide correct path:
php /path/to/project/folder/yii test

"Unable to dump a service container if a parameter is an object or a resource."

I'm writing a bundle that deals with a lot of dates and times and I'm not sure it's particularly possible to easily represent this easily with Yaml or XML. For the configuration I'm defining it as a PHP file, included() into the ...Extension::Load() function:
<?php
// {BundleName}Extension.php
$openingHours = require $path->locate('business_days.php');
$container->setParameter($alias . '.days', $openingHours['days']);
// business_days.php:
return array(
'days' => array(
Carbon::MONDAY => array(
'name' => 'Monday',
'start' => (new Carbon('09:00'))->setDate(0, 0, 0)),
'end' => (new Carbon('17:00'))->setDate(0, 0, 0)),
),
....
);
When the system runs the configuration though (and successfully prepares the config), it then goes to dump the data to the file cache --
"Unable to dump a service container if a parameter is an object or a resource."
How can I - for this bundle - not have the configuration cached to disk, and so avoid the above error?
I don't think it is practical to turn off config caching on a per bundle basis. Use a factory instead.
Code is untested:
class BusinessDaysFactory
{
static function create()
{
return array(
'days' => array(
Carbon::MONDAY => array(
'name' => 'Monday',
'start' => (new Carbon('09:00'))->setDate(0, 0, 0)),
'end' => (new Carbon('17:00'))->setDate(0, 0, 0)),
),
....
# services.yml
business_days:
class: NeedAnEntry_ButItIsNotUsed
factory_class: Namespace\BusinessDaysFactory
factory_method: create
http://symfony.com/doc/current/components/dependency_injection/factories.html

Resources