Avatar of compsol1993
compsol1993
 asked on

PHP Website / MySQL Database Delay

Hello,

I have a simple web app built in PHP.  

There is a data entry form (for entering numeric values).  When the user clicks submit, and INSERT statement is executed, and the user is automatically directed (via HTML redirect) to the grid view of said data.

We ran this system off of an older Mandriva 2007 server, and it worked perfectly.  Data was immediately entered into the database, and upon viewing the Grid, the data was there.

We've migrated to a new server, and found the following:  
-After inserting and redirecting to the grid, the new data is not on the grid
-I immediately check the MySQL database, and see the data is inserted
-If I continuously refresh the PHP grid, within 30-45 seconds, the data appears.

I need to make this data show up immediately.  Since the data is in the database, immediately after clicking submit, I'm not sure why the data wouldn't immediately show up on the PHP grid.

I am populating the grid with a simple SELECT statement, that worked perfectly on the last server.

Any thoughts, is there anything about the newer MySQL or Apache (PHP) that would explain this, perhaps a setting I need to change?

Thanks
PHPMySQL ServerWeb Development

Avatar of undefined
Last Comment
compsol1993

8/22/2022 - Mon
sshah254

Do a test ... can you retrieve older data within a few seconds?

Is this a delay only for newly inserted data?  Or is it a delay for everything across the board?

Ss
compsol1993

ASKER
It's only for newly inserted data.

Also, I've been entering a lot of test data to learn more about the problem.  If I delete the row from the database, it still shows up on the PHP page for approx 1 minute before disappear.  It's almost like the PHP isn't pulling from the live database every time.

It's more like the PHP will only try for new data every minute, otherwise it returns old data.

I've never seen this before.
ASKER CERTIFIED SOLUTION
Francisco Igor

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Zyloch

From the information given, I agree with fraigor that it is likely a caching problem. If that is the case, where the caching takes place needs to be figured out. What happens when you refresh your page using Ctrl+F5?
Your help has saved me hundreds of hours of internet surfing.
fblack61
compsol1993

ASKER
Ok.  I will try the Ctrl+F5, but it's odd this same code worked fine on the old server
compsol1993

ASKER
Hi, you were right, a Ctrl+F5 does cause the data to show immediately.

So I guess the question is now, how do I force this type of refresh in the PHP or HTML code?

fraigor -- are you saying I should add those two lines of code to each page?

Thanks
Zyloch

You can try fraigor's suggestion and add those headers at the top of each page (after any session_start() code). You should check what headers your server is sending; on Firefox you can sniff headers using the LiveHTTPHeaders extension.

Another quick and dirty way to force no caching in most cases is to append a random query string to the end of each page request, e.g. index.php?rand=323432, which should often prevent caching. This is a rather ugly solution, so any solution fixing headers should be better.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
compsol1993

ASKER
Thanks