On May 4, 2011, at 09:06, ojonam wrote:

> I have a view bookprices.ctp, which shows a list of books (12 books), and for 
> each of these books, fires an ajax call to "books/getprice" (controller 
> books, action getprice), in order to get the price of the book. While the 
> prices are not loaded, I have a little "loading" gif show up instead of the 
> price. The ajax call is done by calling a "getPrice" javascript function, 
> which is coded in the bookprices.ctp file, and uses prototype.js.
> 
> Testing with Firebug, I noticed that all calls to getPrice are fired at the 
> same time, which is expected behaviour. However, the results arrive 
> *sequentially*. Only after getting the price of the first book is it possible 
> to query the "books/getprice" url again.
> Doing the same test without cakephp, I notice that things happen in parallel, 
> which is the desired behaviour (and this is what made me think that the 
> problem might be with cake).
> 
> My question is therefore:
> - how can I tell cake to handle requests in an asynchronous manner ?
> - if the above is not possible, how do I redesign my files so that I get the 
> desired behaviour here?

You've discovered a feature of PHP; this is not specific to CakePHP.

Only one request can use the session at once. (And CakePHP does like to use the 
session.)

If you are certain your requests do not need to use the session, tell PHP not 
to open the session in the first place. Or if you can get any required info out 
of the session up front and then close the session while you do your database 
queries for the results (if you're sure you don't need to write anything to the 
session later), then you can tell PHP to close the session early, instead of 
waiting for PHP to close it for you at the end of the request, and thus allow 
the next request to start more quickly.

http://www.thedeveloperday.com/anti-asynchronous-ajax-calls-and-php-sessions/



-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to