Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/03/2017, 08:47
BlackJccl1
 
Fecha de Ingreso: abril-2015
Mensajes: 304
Antigüedad: 9 años, 1 mes
Puntos: 2
Mejorar tiempo para upload con imagenes

tengo mi aplicación para publicar anuncios donde se suben imágenes cuando estos se publican, mi problema esta que tarda de 30 segundos a 1 minuto en subir lo cual es mucho tiempo de espera para un usuario, bueno esto no ocurría antes de que agregase el plugin ImageTool Component de Cakephp aquí mi codigo

Código PHP:
Ver original
  1. ini_set('memory_limit', '256M');
  2. require_once(ROOT . DS . 'vendor' . DS . 'ImageTool.php');
  3. use ImageTool;
  4. class AdvertisementsController extends AppController{
  5.  
  6. private function _resizeImage($image,$output){
  7.     $img = ImageTool::resize(array(
  8.                     'input' => $image,
  9.                     'output' => $output,
  10.                     'width' => 100,
  11.                     'height' => 100,
  12.                     'keepRatio' => true,
  13.                 ));
  14.     $img = ImageTool::autorotate(array(
  15.         'input' => $image,
  16.         'output' => $output,
  17.         'degrees' => 360
  18.     ));
  19.     return $img;
  20. }
  21.  
  22. public function publicadd() {
  23.  
  24. $publicadd = $this->Advertisements->newEntity($this->request->data);
  25.     if($this->request->is('post')){
  26.         $publicadd->id_user = $this->Auth->user('id_user');
  27.         $publicadd = $this->Advertisements->patchEntity($publicadd,$this->request->data);
  28.         if ($this->Advertisements->save($publicadd)) {
  29.             $id = $publicadd->id_advertisement;
  30.             $publicaddimg = $this->AdvertisementsImagenes->query();
  31.             $images = $this->request->data['name_imagen'];
  32.             new Folder(WWW_ROOT . 'anuncios/',true,0755);
  33.             foreach ($images as $image){
  34.                 $data = [
  35.                     'id_advertisement' => $id,
  36.                     'name_imagen' => $image['name'],
  37.                     'upload_date' => date("Y-m-d")
  38.                 ];
  39.                 $publicaddimg->insert(['id_advertisement','name_imagen','upload_date'])
  40.                         ->values($data);
  41.                 $imgname = $image['tmp_name'];
  42.                 $img = $this->_resizeImage($imgname, WWW_ROOT.'anuncios'.DIRECTORY_SEPARATOR.$publicadd->id_user.DIRECTORY_SEPARATOR.date("Y-m-d").DIRECTORY_SEPARATOR.$image['name']);
  43.             }
  44.             $publicaddimg->execute();
  45.             $this->Flash->success('Anuncio Publicado');
  46.             $this->redirect(['controller' => 'Home','action' => 'index']);
  47.         }else{
  48.             $this->Flash->error('Error al momento de guardar el registro');
  49.         }
  50.     }
  51.     $this->set('advertisements',$publicadd);
  52.     $query_categories = $this->Categories->find('list');
  53.     $this->set('categories',$query_categories);
  54.     $query_articles_states = $this->StatesArticles->find('list');
  55.     $this->set('states',$query_articles_states);
  56. }
  57. }

Todo lo hace bien el tema esta que se tarda y antes de agregar el plugin, era rápido por favor ayuda algo mas me debe de faltar