Is CakePHP unable to handle multiple Ajax requests simultaneously?

After multiple rounds of editing this post, I keep uncovering new information through testing and debugging. Here is my current situation:

I have a method thinker that takes a significant amount of time to process. To address this, I have decided to call it via Ajax and display an indicator to the user, which works perfectly.

Additionally, I want to show the user the progress of the "thinking" process, either in percentage or ticks.

This task is not too challenging as the thinker function has a loop that saves new thoughts to the database in each iteration.

Essentially, the counter displays the number of "thoughts" associated with a specific ID.

The issue arises when the callback option fails to trigger.

To simplify, the callback only executes twice - before the request (displaying zero) and after the thinker completes its task (showing the full count).

Here is the basic code:

<span id="indicator" style="display: none;"><img src="/img/ajax-loader.gif" alt="" /></span>
<span id="progress"></span>
<span id="clicker" style="cursor: pointer;">Do it!</span>

<script type="text/javascript">
//<![CDATA[
Event.observe('clicker', 'click', function(event) {
  new Ajax.Request(
    '/examples/thinker/123', 
    {asynchronous:true, evalScripts:true, onComplete:function(request, json) {Element.hide('indicator');}, onLoading:function(request) {Element.show('indicator');}}
    );
  new Ajax.PeriodicalUpdater(
    'progress', 
    '/examples/counter/123', 
    {asynchronous:true, evalScripts:true, frequency: 2}
    );
  });
//]]>
</script>

UPDATE:

Using the Firebug XHR console, I delved deeper into this issue. I even tried using jQuery for testing, but it did not resolve the problem.

It seems the problem lies with CakePHP. When I replicated the scenario with basic PHP, everything worked simultaneously. However, with CakePHP, the counter is called first, followed by the thinker, and then the counter is updated every two seconds but only responds after the thinker completes.

Could it be that CakePHP cannot handle the second request until the first is finished?

Best regards, Paul

Answer №1

It appears that the issue lies in CakePHP. By default, CakePHP saves sessions in files, which is the default setting in php.ini. This means that only one user can run two CakePHP instances simultaneously with the default session storage option.

However, changing the following configuration setting:

Configure::write('Session.save', 'php');

to

Configure::write('Session.save', 'cache');

Seems to resolve the issue.

Answer №2

Cake can't be blamed in this situation. The culprit might be your server, although it's not very likely. It's more possible that your script is causing a lock on the database, preventing it from being accessed again. I'm not an expert in this field, so I'm just speculating, but I suggest looking into maintaining a persistent connection and possibly closing and reopening the connection between each loop. Transactions should also be checked, although I personally have not encountered this issue before.

To investigate further, it's best to isolate and test each component individually.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS controller exceeding allowed complexity (SonarLint alert)

While utilizing SonarLint in Eclipse, I encountered an issue while working on an AngularJS application. Specifically, I was cleaning up a controller to improve readability when SonarLint flagged the following problem: The function has a complexity of 11 ...

How can I determine the Windows service pack version directly from my web browser?

Is there a method to determine the installed service pack from the browser? It doesn't seem to be available in System.Web.HttpBrowserCapabilities in asp.net. I am looking for a solution to alert users about the necessity of updating to XP Service Pack ...

Why is mysqli_insert_id() not returning any value even though the database insert was successful?

Despite searching for answers, I haven't found a solution to my problem. The auto-increment id has no default value and serves as the PRIMARY KEY After executing an AJAX query with posted data, the insertion works smoothly. The function also success ...

Tips for effortlessly enlarging an element

When you click on "#sidebarnav>li", the following happens: 1) The second child of it - <ul> element will expand and its class toggles between "collapse" and "collapse in". 2) "#sidebarnav>li" will receive the "active" class. 3) The "aria-ex ...

Error: The variable "helloSpeaker" has not been declared

As a newcomer to JavaScript, I have been struggling to get my code working. Even after defining jQuery, the issue persists, displaying the error message: Uncaught ReferenceError: helloSpeaker is not defined (function(window) { var helloSpeaker = {}; ...

Deactivate the rest of the buttons by utilizing the e.target.id

I have ten expansion panels. When I click a button in one expansion panel, I want to disable other buttons in the remaining expansion panels. The issue is that when I try to target an id, it does not return e.target.id but instead returns as the value pass ...

Author Names Missing from Book List in Locallibrary Tutorial

After spending several years working on front-end development, I've decided to delve into back-end development to expand my skill set. Following the Basic Node and Express course from FreeCodeCamp Curriculum, I am now following the MDN Express Localli ...

The prop type `cellHeight` provided to `GridList` in (Material-ui / React) is invalid

warning.js:33 Warning: The prop type for cellHeight in the GridList component is invalid. I encountered this error message, despite the property functioning correctly. Is there a way to resolve this issue? If you're interested, check out the documen ...

What kind of error should be expected in a Next.js API route handler?

Recently, I encountered an issue with my API route handler: import { NextRequest, NextResponse } from "next/server"; import dbConnect from "@/lib/dbConnect"; import User from "@/models/User"; interface ErrorMessage { mess ...

Exploring 2 attributes within a specific Drupal content category

Having some trouble implementing a search form on my Drupal site. I have a content type with multiple fields and I'm looking to create a form that can search within both the title and body, then display a list of results including the title, picture, ...

Adjust the size of the font for the placeholder text

I've been attempting to adjust the font size of the placeholder text. I added the font size property to the listed classes below, but for some reason, it's not taking effect. Could you please advise me on how to resolve this issue so that I can ...

Identifying the moment when attention shifts away from an element

Is it possible to detect when focus occurs outside an element without relying on global selectors like $(document), $(body), or $(window) for performance reasons? If achieving this without global selectors is not feasible, provide a provable reason expla ...

What is the best way to navigate to a different page without triggering the default behavior with prevent

Is there anyone who can assist me in redirecting to another page (specifically, the "cart page")? I am currently using preventDefault() to ensure validation before redirecting, but even after validation, I am still stuck on the same page. Can someone pleas ...

Sharing scope variables between multiple dynamically created directives

Find my Plunkr example here: http://plnkr.co/edit/9LcYbn1468miu5McgPqR?p=preview I successfully added the form to the variable inside the options parameter, but I am looking to bind it to a different location outside of the options parameter. I have a cu ...

Switching between height: 0 and height:auto dynamically with the power of JavaScript and VueJS

Currently, I am changing the height of a container from 0px to auto. Since I do not know the exact final height needed for the container, using max-height could be an option but I prefer this method. The transition from 0 to auto works smoothly, however, ...

Tips on efficiently adding and removing elements in an array at specific positions, all the while adjusting the positions accordingly

My challenge involves an array of objects each containing a position property, as well as other properties. It looks something like this: [{position: 1, ...otherProperties}, ...otherObjects] On the frontend, these objects are displayed and sorted based on ...

Troubleshooting a timing loop problem with jQuery Ajax and setInterval when using flipCounter's onAnimationStopped feature

In the code below, I am retrieving some data to use for a counter. The problem is that after the initial page load and one interval, things start to go haywire. The calls are made without any delay and the counter cannot react before the next call is made. ...

How can you use ng-click to re-sort data that has already been loaded using Angular's ng-click?

I'm having trouble switching between loading and sorting the information in the table using ng-click. The functions to load and sort work correctly individually, but I can't seem to switch between the two. It seems like I reset the countries data ...

What is the reason for JavaScript documentation using a nested array to define a function's parameters in its syntax?

I'm struggling to articulate my question, but as I delve into the documentation for JavaScript and Node.js, I notice they define syntax in a way such as this. var new_array = old_array.concat(value1[, value2[, ...[, valueN]]]) It seems like all th ...

TS1057: It is required that an async function or method has a return type that can be awaited

There was a recent Github issue reported on March 28th regarding async arrow functions generating faulty code when targeting ES5, resulting in the error message: TS1057: An async function or method must have a valid awaitable return type You can find t ...