tamir
tamir

Reputation: 3297

Fast ajax responses in Symfony2

I have a tagging text field that while typing in a new tag, suggests similar existing tags. The suggestions are retrieved by an ajax request to a controller which pulls them with from the DB with Doctrine. i.e:

The problem is that the request is too slow (atleast 2 seconds, in prod) which in this case is too much.

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

Upvotes: 4

Views: 1998

Answers (3)

tamir
tamir

Reputation: 3297

For small pages such as ajax autocomplete I decided to use Silex which is a micro Symfony2 and it gets me an elegant and fast solution.

Upvotes: 0

Charles-Antoine Fournel
Charles-Antoine Fournel

Reputation: 1783

if kernel.request is slow , it's not necessarly a symfony side issue.

you should look to optimize your server by updating your Apache with php-fastPGM instead of php standard module.

you should also activate a cache manager like php APC which reduce a few more the requests .

for example i run a symfony project on a raspberry pi . Before these tweaks , one request with 8 database request took around 25 seconds to display. After these tweaks, a page was displayed in less than 3 seconds ( an average of 2.5 s )

another list of possible tweaks :

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

Upvotes: 1

user1452962
user1452962

Reputation: 386

You could ask doctrine(if you're not already doing so) to fetch the result as array(without converting your whole query to a bunch of objects) by using:

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

Should speed up things a little.

Upvotes: 0

Related Questions