Symfony - image in response - speed, optimization

I generate dynamic graphics in my controller:

  • If the file does not exist (unique file name), then create the graphic and save it

  • return RedirectResponse ($ url)

(3. I also tried:

    $fp = fopen($url, "rb");
    $str = stream_get_contents($fp);
    fclose($fp);

    $response = new Response($str, 200);
    $response->headers->set('Content-Type', 'image/png');
    return $response;

)

I need it to generate dynamic user panels for users [in this graph, some text will be automatically updated if some changes are made to my sites].

, script /bandwitch. , . , , , , Chrome (F12), , (2. 3.) ~ 1 ( [ .. url .png] 44 ).

, ~ 1 , , , , 1000 , -, .

, , - ?

PS. - , url , smth/username/userbar/insted smth/img/userbars/cache/blabla.png. , :).

EDIT: : , , ( , ftp) 1 , , , ,

           <img src="direct_url_to_png"> 

44 .

+5
1

Varnish , Varnish - - HTTP, -. , .

, memcache, redis. , , , Larnish, IO.

, , , - PHP, , , " ";)

, , :

<?php
class MyClass
{
  function __construct()
  {
     $this->timer = array(
       'start' => microtime(True);
     );
   }

  function myAction()
  {
    $this->timer['startaction'] = microtime(True);

    $fp = fopen($url, "rb");
    $this->timer['startstream'] = microtime(True);
    $str = stream_get_contents($fp);
    fclose($fp);
    $this->timer['endstream'] = microtime(True);

    $response = new Response($str, 200);
    $response->headers->set('Content-Type', 'image/png');

    $this->timer['endaction'] = microtime(True);
    print_r($this->timer)
    return $response;
  }
}

, - HTML/CSS . , , , .

+3

All Articles