Ajax quick answers in Symfony2

I have a text box for tags that when entering a new tag offers similar tags. Suggestions are retrieved using an ajax request to the controller, which retrieves them from the database using Doctrine. i.e:

  • Request /tags/suggestions?q=foo
  • Reply ["foo","food","fool"]

The problem is that the request is too slow (at least 2 seconds in prod), which in this case is too large.

Is there a way to speed up the request? According to the profiler, kernel.request with 50% of the total time is the main consumer of time.

+4
source share
3 answers

If kernel.request is slow, this is not necessarily a problem with symfony.

you must optimize your server by upgrading Apache with php-fastPGM instead of the standard php module.

you must also activate the cache manager, e.g. php APC, which reduces a few more requests.

For example, I am running a symfony project on a raspberry pi. Before these settings, one query with 8 database queries took about 25 seconds to display. After these settings, the page was displayed in less than 3 seconds (average 2.5 s)

another list of possible settings:

http://slides.liip.ch/static/2012-05-18_symfony-speed.html#9

+1
source

You can request the teaching (if you have not done so already) to get the result as an array (without converting your entire request into a bunch of objects) using:

 $q = $em->createQueryBuilder('t')->(...); $q -> getQuery() -> fetchArrayResult(); 

We need to speed things up a bit.

0
source

For small pages, such as ajax autocomplete, I decided to use Silex , which is a symfony2 microsymbol, and it gives me an elegant and quick solution.

0
source

All Articles