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
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
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
ASKER
Ok. I will try the Ctrl+F5, but it's odd this same code worked fine on the old server
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
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
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.
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.
ASKER
Thanks
Is this a delay only for newly inserted data? Or is it a delay for everything across the board?
Ss