We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Incremental Issue

Hi,

I seem to be having a peculiar issue when it comes to incrementing the value of something. Here's an example of what I am referring to. Let's say I have 2 blocks on my website. Statistics and recent searches. The following are the statistics being tracked in the statistics block:

Total Names Total Searches Searches Today Total Users

My issue is that total searches increments as expected(each search adds +1) to the total. However, for searches today, it's off compared to the recent searches. If I was to type the following: Apple, Orange, Dog, Cat. The result of searches today isn't adding +4 but rather +2. I am unsure as to why.

A working demo of the issue in question can be found by going to https://maxcape.com. Any help is appreciated in addressing this issue.

Thanks.

Difficult without seeing the code. I assume that when someone hits the search controller i.e. performing a search, you increment the recent search counter by one as well as the today search countery by one so that you can show them in your view. Those values are stored somewhere (perhaps db or cache) and then used to display the block on the site.

It could very well be a timing issue i.e. one operation tries to update the counter while the other one hasn't finished writing to the counter field and as a result operation A gets overwritten by operation B.