PHP Website / MySQL Database Delay

compsol1993
compsol1993 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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

Author

Commented:
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.
Developer
Commented:
There could be a browser "cache" problem,..
Check if the grid page is sending some "expiration" header to tell the browser that the page needs to refresh.


header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Top Expert 2004

Commented:
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?

Author

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

Author

Commented:
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
Top Expert 2004

Commented:
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.

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial